|
@@ -108,81 +108,17 @@ func (a *AuthController) GetEtaToken(c *gin.Context) {
|
|
|
return
|
|
|
}
|
|
|
|
|
|
- var token string
|
|
|
- account := utils.MD5(adminName)
|
|
|
- // 获取用户未过期的session, 避免过于频繁生成token
|
|
|
- expired := time.Now().AddDate(0, 0, 1).Format(utils.FormatDateTime)
|
|
|
- session, _ := eta.GetUserUnexpiredSysSession(adminName, expired)
|
|
|
- if session != nil && session.AccessToken != "" {
|
|
|
- token = session.AccessToken
|
|
|
- } else {
|
|
|
- token = utils.GenToken(account)
|
|
|
- sysSession := new(eta.SysSession)
|
|
|
- sysSession.UserName = adminName
|
|
|
- sysSession.SysUserId = sysUser.AdminId
|
|
|
- sysSession.ExpiredTime = time.Now().AddDate(0, 0, 90)
|
|
|
- sysSession.IsRemember = 1
|
|
|
- sysSession.CreatedTime = time.Now()
|
|
|
- sysSession.LastUpdatedTime = time.Now()
|
|
|
- sysSession.AccessToken = token
|
|
|
- if e := eta.AddSysSession(sysSession); e != nil {
|
|
|
- resp.FailMsg("获取失败", "新增session失败, err: "+e.Error(), c)
|
|
|
- return
|
|
|
+ // 生成登录session
|
|
|
+ respResult, _, err, errMsg := services.CreateEtaSession(sysUser)
|
|
|
+ if err != nil {
|
|
|
+ if errMsg == `` {
|
|
|
+ errMsg = "获取失败"
|
|
|
}
|
|
|
+ resp.FailMsg("获取失败", "生成登录session失败, err: "+e.Error(), c)
|
|
|
+ return
|
|
|
}
|
|
|
|
|
|
- login := new(response.LoginResp)
|
|
|
- login.Authorization = token
|
|
|
- login.Authorization = "authorization=" + token + "$account=" + account
|
|
|
- login.RealName = sysUser.RealName
|
|
|
- login.AdminId = sysUser.AdminId
|
|
|
- login.AdminName = sysUser.AdminName
|
|
|
- login.RoleName = sysUser.RoleName
|
|
|
- login.SysRoleTypeCode = sysUser.RoleTypeCode //系统角色编码
|
|
|
- login.RoleTypeCode = sysUser.RoleTypeCode
|
|
|
- login.Authority = sysUser.Authority
|
|
|
-
|
|
|
- // 判断实际的角色类型
|
|
|
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_GROUP {
|
|
|
- login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
|
|
|
- }
|
|
|
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_TEAM {
|
|
|
- login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
|
|
|
- }
|
|
|
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_FICC_DEPARTMENT {
|
|
|
- login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
|
|
|
- }
|
|
|
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_GROUP {
|
|
|
- login.RoleTypeCode = utils.ROLE_TYPE_CODE_RAI_SELLER
|
|
|
- }
|
|
|
- if sysUser.RoleTypeCode == utils.ROLE_TYPE_CODE_RAI_DEPARTMENT {
|
|
|
- login.RoleTypeCode = utils.ROLE_TYPE_CODE_RAI_SELLER
|
|
|
- }
|
|
|
- if sysUser.RoleName == utils.ROLE_NAME_FICC_DIRECTOR {
|
|
|
- login.RoleTypeCode = utils.ROLE_TYPE_CODE_FICC_SELLER
|
|
|
- }
|
|
|
-
|
|
|
- // 角色产品ID
|
|
|
- productId := services.GetProductId(sysUser.RoleTypeCode)
|
|
|
- productIdName := map[int]string{
|
|
|
- 0: "admin",
|
|
|
- utils.COMPANY_PRODUCT_FICC_ID: utils.COMPANY_PRODUCT_FICC_NAME,
|
|
|
- utils.COMPANY_PRODUCT_RAI_ID: utils.COMPANY_PRODUCT_RAI_NAME,
|
|
|
- }
|
|
|
- login.ProductName = productIdName[productId]
|
|
|
-
|
|
|
- // 新增登录记录
|
|
|
- {
|
|
|
- record := new(eta.SysUserLoginRecord)
|
|
|
- record.Uid = sysUser.AdminId
|
|
|
- record.UserName = adminName
|
|
|
- record.Ip = c.RemoteIP()
|
|
|
- record.Stage = "login"
|
|
|
- record.CreateTime = time.Now()
|
|
|
- go eta.AddSysUserLoginRecord(record)
|
|
|
- }
|
|
|
-
|
|
|
- resp.OkData("获取成功", login, c)
|
|
|
+ resp.OkData("获取成功", respResult, c)
|
|
|
}
|
|
|
|
|
|
// GetCrmToken
|