Explorar el Código

fix(登录逻辑):调整登录逻辑

Roc hace 3 años
padre
commit
180ce65608
Se han modificado 2 ficheros con 13 adiciones y 26 borrados
  1. 9 26
      controllers/admin.go
  2. 4 0
      services/admin.go

+ 9 - 26
controllers/admin.go

@@ -4,7 +4,6 @@ import (
 	"encoding/json"
 	"hongze/hongze_mobile_admin/models/request/admin"
 	admin3 "hongze/hongze_mobile_admin/models/response/admin"
-	admin2 "hongze/hongze_mobile_admin/models/tables/admin"
 	"hongze/hongze_mobile_admin/models/tables/h5_admin_session"
 	"hongze/hongze_mobile_admin/services"
 	"hongze/hongze_mobile_admin/utils"
@@ -36,38 +35,22 @@ func (this *AdminCommon) Login() {
 		return
 	}
 
-	sysUser, err := admin2.CheckAdmin(req.Username, req.Password)
-	if err != nil {
-		if err.Error() == utils.ErrNoRow() {
-			this.FailWithMessage("登录失败,账号或密码错误", "登录失败,账号或密码错误,Err:"+err.Error())
-			return
-		}
-		this.FailWithMessage("登录失败,账号或密码错误", "登录失败,Err:"+err.Error())
-		return
-	}
-	if sysUser == nil {
-		this.FailWithMessage("登录失败,账号或密码错误", "登录失败,admin_wx is nil")
-		return
-	}
-	if sysUser.Enabled == 0 {
-		this.FailWithMessage("您的账号已被禁用,如需登录,请联系管理员", "您的账号已被禁用,如需登录,请联系管理员")
-		return
-	}
-	err = h5_admin_session.UpdateSession(this.Session.SessionId, sysUser.AdminId, time.Now().AddDate(0, 0, 90))
+	adminWx, err := services.BindWxUser(this.Session.OpenId, req.Username, req.Password, utils.WxPlatform)
+	err = h5_admin_session.UpdateSession(this.Session.SessionId, adminWx.AdminId, time.Now().AddDate(0, 0, 90))
 	if err != nil {
 		this.FailWithMessage("登录失败", "变更session信息失败,Err:"+err.Error())
 		return
 	}
 	resp := admin3.LoginResp{
-		RealName:     sysUser.RealName,
-		AdminName:    sysUser.AdminName,
-		RoleName:     sysUser.RoleName,
-		RoleTypeCode: sysUser.RoleTypeCode,
+		RealName:     adminWx.RealName,
+		AdminName:    adminWx.AdminName,
+		RoleName:     adminWx.RoleName,
+		RoleTypeCode: adminWx.RoleTypeCode,
 	}
 
-	resp.AdminId = sysUser.AdminId
+	resp.AdminId = adminWx.AdminId
 	var productName string
-	productId := services.GetProductId(sysUser.RoleTypeCode)
+	productId := services.GetProductId(adminWx.RoleTypeCode)
 
 	if productId == 1 {
 		productName = utils.COMPANY_PRODUCT_FICC_NAME
@@ -77,6 +60,6 @@ func (this *AdminCommon) Login() {
 		productName = "admin"
 	}
 	resp.ProductName = productName
-	resp.Authority = sysUser.Authority
+	resp.Authority = adminWx.Authority
 	this.OkDetailed(resp, "登录成功")
 }

+ 4 - 0
services/admin.go

@@ -127,6 +127,10 @@ func BindWxUser(openid, userName, password string, registerPlatform int) (adminW
 		}
 		return
 	}
+	if adminInfo.Enabled == 0 {
+		err = errors.New("您的账号已被禁用,如需登录,请联系管理员")
+		return
+	}
 
 	//获取用户信息
 	adminWx, err = admin.GetAdminWxById(adminInfo.AdminId)