|
@@ -28,6 +28,7 @@ type Front struct {
|
|
|
login xweb.Mapper `xweb:"/"` //登录页面
|
|
|
code xweb.Mapper `xweb:"/code"` //获取图片验证码
|
|
|
sendVerifyCode xweb.Mapper `xweb:"/sendVerifyCode"` //获取手机验证码
|
|
|
+ chooseEnt xweb.Mapper `xweb:"/chooseEnt"` //选择企业
|
|
|
|
|
|
index xweb.Mapper `xweb:"/front/index"` //index页面
|
|
|
logout xweb.Mapper `xweb:"/front/logout"` //注销
|
|
@@ -94,8 +95,6 @@ func (f *Front) Login() {
|
|
|
return
|
|
|
}
|
|
|
realPhoneCode := qu.ObjToString(session.Values["code"])
|
|
|
- log.Println("realPhoneCode", realPhoneCode)
|
|
|
- log.Println("param.phoneCode", phoneCode)
|
|
|
sessionPhone := qu.ObjToString(session.Values["phone"])
|
|
|
if sessionPhone == "" {
|
|
|
log.Printf("短信验证码过期-%s \n", phone)
|
|
@@ -124,8 +123,8 @@ func (f *Front) Login() {
|
|
|
log.Println("验证码验证通过")
|
|
|
// 3. 验证用户导出权限 确认认用户是否有数据导出权限
|
|
|
loginUser := JyMysql.SelectBySql("select id, name,ent_id,phone,export_power,name from entniche_user where phone=? and export_power=1", phone)
|
|
|
- if len(*loginUser) == 0 || ((*loginUser)[0])["phone"] != phone {
|
|
|
- log.Println("无权限")
|
|
|
+ if len(*loginUser) == 0 {
|
|
|
+ log.Println("该用户无数据导出权限")
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
"code": 0,
|
|
|
"status": false,
|
|
@@ -133,59 +132,62 @@ func (f *Front) Login() {
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- // 4. 根据用户的企业id查询对应的管理员手机号 根据管理员手机号查询jyqyfw的企业表对应的appid 放到session里 以及确认用户角色
|
|
|
- log.Println((*loginUser)[0]["ent_id"], "=====================")
|
|
|
- entInfo := JyMysql.SelectBySql("select phone,name from entniche_info WHERE id = ?", (*loginUser)[0]["ent_id"])
|
|
|
- if len(*entInfo) == 0 {
|
|
|
+ // 4. 如果用户在多个企业并且都有剑鱼库里都有数据导出权限,则返回去让用户选择企业
|
|
|
+ if len(*loginUser) > 1 {
|
|
|
+ f.SetSession("user", map[string]interface{}{
|
|
|
+ "phone": phone,
|
|
|
+ })
|
|
|
f.ServeJson(map[string]interface{}{
|
|
|
- "code": 0,
|
|
|
- "status": false,
|
|
|
- "message": "企业信息查询失败",
|
|
|
+ "code": 1,
|
|
|
+ "status": true,
|
|
|
+ "message": "",
|
|
|
})
|
|
|
return
|
|
|
- }
|
|
|
- var role int // 角色 1 管理员 3 普通用户
|
|
|
- // 判断当前用户手机号是否是管理员手机号
|
|
|
- if phone != qu.ObjToString((*entInfo)[0]["phone"]) {
|
|
|
- role = 3
|
|
|
- } else {
|
|
|
- role = 1
|
|
|
- }
|
|
|
- // 查询mongo企业信息库 获取appid
|
|
|
- query := bson.M{
|
|
|
- "phone": qu.ObjToString((*entInfo)[0]["phone"]),
|
|
|
- "username": qu.ObjToString((*entInfo)[0]["name"]),
|
|
|
- }
|
|
|
- entMgoInfo, ok := MgoCus.FindOne("user", query)
|
|
|
- if !ok {
|
|
|
- // 企业信息查询失败
|
|
|
- return
|
|
|
- }
|
|
|
- //相关信息存入session
|
|
|
- if entMgoInfo != nil && len(*entMgoInfo) > 0 {
|
|
|
- f.SetSession("user", map[string]interface{}{
|
|
|
- "name": (*loginUser)[0]["name"],
|
|
|
- "phone": phone,
|
|
|
- "role": role,
|
|
|
- "appid": (*entMgoInfo)["appid"],
|
|
|
- "ent_id": (*loginUser)[0]["entid"],
|
|
|
- "id": (*loginUser)[0]["id"],
|
|
|
- })
|
|
|
- //UserMenu[email] = GetUserMenu(qu.ObjToString((*user)["s_role"]))
|
|
|
|
|
|
}
|
|
|
- fmt.Println("role", role)
|
|
|
- f.ServeJson(map[string]interface{}{
|
|
|
- "code": 0,
|
|
|
- "status": true,
|
|
|
- "role": role,
|
|
|
- "message": "",
|
|
|
- })
|
|
|
+ fmt.Println()
|
|
|
+ LoginCheck(f, strconv.Itoa(int((*loginUser)[0]["ent_id"].(int64))), (*loginUser)[0], phone)
|
|
|
+ return
|
|
|
} else {
|
|
|
f.Render("login.html")
|
|
|
}
|
|
|
}
|
|
|
+func (f *Front) ChooseEnt() {
|
|
|
+ defer qu.Catch()
|
|
|
+ // 选择企业页面
|
|
|
+ tempSession := f.GetSession("user")
|
|
|
+ if tempSession == nil || tempSession == "" {
|
|
|
+ f.Redirect("/", 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ info := tempSession.(map[string]interface{})
|
|
|
+ if info["phone"] == "" || info["phone"] == nil {
|
|
|
+ f.Redirect("/", 302)
|
|
|
+ return
|
|
|
+ }
|
|
|
+ if f.Method() == "POST" {
|
|
|
+ entId := f.GetString("ent_id")
|
|
|
|
|
|
+ // 2. 确认该手机号有数据导出权限
|
|
|
+ loginUser := JyMysql.SelectBySql("select id, name,ent_id,phone,export_power,name from entniche_user where phone=? and export_power=1 and ent_id=?", info["phone"], entId)
|
|
|
+ if len(*loginUser) == 0 {
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "code": 0,
|
|
|
+ "status": false,
|
|
|
+ "message": "无权限",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ LoginCheck(f, entId, (*loginUser)[0], info["phone"].(string))
|
|
|
+ return
|
|
|
+ } else { // get 请求时铺企业页面
|
|
|
+ // 查询 企业信息 name ent_id
|
|
|
+ rs := JyMysql.SelectBySql("select a.ent_id, b.name ent_name from entniche_user a, entniche_info b WHERE a.phone =? and export_power=1 and a.ent_id=b.id", info["phone"])
|
|
|
+ f.T["ent_info"] = rs
|
|
|
+ f.Render("choose_ent.html", &f.T)
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
func (f *Front) Index() {
|
|
|
defer qu.Catch()
|
|
|
f.Render("index.html")
|
|
@@ -388,8 +390,6 @@ func (f *Front) SendVerifyCode() {
|
|
|
})
|
|
|
return
|
|
|
}
|
|
|
- fmt.Println("code", code)
|
|
|
- fmt.Println("img", imgCode)
|
|
|
if !captcha.VerifyString(code, imgCode) {
|
|
|
log.Printf("图片验证码错误-%s \n", phone)
|
|
|
f.ServeJson(map[string]interface{}{
|
|
@@ -401,7 +401,6 @@ func (f *Front) SendVerifyCode() {
|
|
|
}
|
|
|
//3. 验证手机号是否存在
|
|
|
user := JyMysql.SelectBySql("select * from entniche_user where phone=? and export_power=1", phone)
|
|
|
- fmt.Println(user, "-----------------================")
|
|
|
// 确认用户是否存在
|
|
|
if len(*user) == 0 || ((*user)[0])["phone"] != phone {
|
|
|
log.Println("没有数据导出权限")
|
|
@@ -468,3 +467,70 @@ func SendSMS(tplcode /*模板代码*/, mobile /*手机号码*/ string, param map
|
|
|
text := strings.Join(tmp, "&")
|
|
|
sms.SendSms(mobile, tplcode, text)
|
|
|
}
|
|
|
+
|
|
|
+func LoginCheck(f *Front, entId string, loginUser map[string]interface{}, userPhone string) {
|
|
|
+ // 1. 确认该企业有使用该系统的权限 查询配置文件appid 确认是否有使用该系统的权限
|
|
|
+ query2 := bson.M{
|
|
|
+ "ent_id": entId,
|
|
|
+ }
|
|
|
+ log.Println(entId)
|
|
|
+ isExist, _ := Mgo.FindOne("datatag_export_config", query2)
|
|
|
+ log.Println(isExist)
|
|
|
+ if len(*isExist) == 0 {
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "code": 0,
|
|
|
+ "status": false,
|
|
|
+ "message": "该企业无权限",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 3. 查询企业管理员信息及手机号
|
|
|
+ entInfo := JyMysql.SelectBySql("select phone,name from entniche_info WHERE id = ?", loginUser["ent_id"])
|
|
|
+ if len(*entInfo) == 0 {
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "code": 0,
|
|
|
+ "status": false,
|
|
|
+ "message": "企业信息查询失败",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 4. mongo库查询与之关联的企业appid
|
|
|
+ query := bson.M{
|
|
|
+ "phone": (*entInfo)[0]["phone"],
|
|
|
+ "username": (*entInfo)[0]["name"],
|
|
|
+ }
|
|
|
+ entMgoInfo, ok := MgoCus.FindOne("user", query)
|
|
|
+ if !ok {
|
|
|
+ // 企业信息查询失败
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "code": 0,
|
|
|
+ "status": false,
|
|
|
+ "message": "appid查询失败",
|
|
|
+ })
|
|
|
+ return
|
|
|
+ }
|
|
|
+ // 5. 确认用户角色
|
|
|
+ var role int // 角色 1 管理员 3 普通用户
|
|
|
+ if userPhone != qu.ObjToString((*entInfo)[0]["phone"]) {
|
|
|
+ role = 3
|
|
|
+ } else {
|
|
|
+ role = 1
|
|
|
+ }
|
|
|
+
|
|
|
+ // 确认用户角色 存session
|
|
|
+ f.SetSession("user", map[string]interface{}{
|
|
|
+ "name": loginUser["name"],
|
|
|
+ "phone": userPhone,
|
|
|
+ "role": role,
|
|
|
+ "appid": (*entMgoInfo)["appid"],
|
|
|
+ "ent_id": entId,
|
|
|
+ "id": loginUser["id"],
|
|
|
+ })
|
|
|
+ // 返回
|
|
|
+ f.ServeJson(map[string]interface{}{
|
|
|
+ "code": 0,
|
|
|
+ "status": true,
|
|
|
+ "role": role,
|
|
|
+ "message": "",
|
|
|
+ })
|
|
|
+}
|