作者 tangxvhui

更新 单点登录处理方式

... ... @@ -584,8 +584,8 @@ func LoginAuthBySecretKey(secretKey string) (protocol.LoginAuthToken, error) {
err error
logintoken protocol.LoginAuthToken
// usercompanyid int64
userdata *models.User
companyData *models.Company
// companyData *models.Company
)
var uclientReturn *ucenter.ResponseLogin
uclientReturn, err = ucenter.RequestUCenterLoginBySecret(secretKey)
... ... @@ -597,28 +597,7 @@ func LoginAuthBySecretKey(secretKey string) (protocol.LoginAuthToken, error) {
},
}
}
userdata, err = models.GetUserByPhone(uclientReturn.Data.Phone)
if err != nil {
log.Debug("GetUserByPhone(%d) err:%s", uclientReturn.Data.Phone, err)
return logintoken, protocol.NewErrWithMessage("10201")
}
companyData, err = models.GetCompanyByUCenter(uclientReturn.Data.CompanyId)
if err != nil {
log.Error("获取company数据失败:%s", err)
return logintoken, protocol.NewErrWithMessage("10211")
}
if companyData.Enable == models.COMPANY_ENABLE_NO {
log.Error("公司未启用机会模块")
return logintoken, protocol.NewErrWithMessage("10212")
}
ucompany, err := models.GetUserCompanyBy(userdata.Id, companyData.Id)
if err != nil {
log.Error("获取user_company失败;%s", err)
return logintoken, protocol.NewErrWithMessage("10202")
}
businessAdminResp, err := serverplatform.GetuserAuthDo(ucompany.Id)
businessAdminResp, err := serverplatform.GetuserAuthDo(uclientReturn.Data.Muid)
if err != nil {
log.Error("向企业平台获取鉴权结果失败,err:%s", err)
return logintoken, protocol.NewErrWithMessage("1")
... ... @@ -635,23 +614,50 @@ func LoginAuthBySecretKey(secretKey string) (protocol.LoginAuthToken, error) {
log.Error("用户没有权限进行操作")
return logintoken, protocol.NewErrWithMessage("10210")
}
logintoken, _ = GenerateAuthToken(userdata.Id, companyData.Id, ucompany.Id)
//更新用户数据
userdata.Accid = uclientReturn.Data.Accid
userdata.Icon = uclientReturn.Data.Avatar
userdata.ImToken = uclientReturn.Data.Imtoken
userdata.NickName = uclientReturn.Data.NickName
userdata.CsAccount = uclientReturn.Data.CustomerAccount
userdata.LastLoginTime = time.Now()
err = models.UpdateUserById(userdata, []string{"Accid", "Icon", "ImToken", "NickName", "CsAccount", "LastLoginTime"})
if err != nil {
log.Error("更新用户user数据失败:%s", err)
}
ucompany.NickName = uclientReturn.Data.NickName
err = models.UpdateUserCompanyById(ucompany, []string{"NickName"})
// userdata, err = models.GetUserByPhone(uclientReturn.Data.Phone)
// if err != nil {
// log.Debug("GetUserByPhone(%d) err:%s", uclientReturn.Data.Phone, err)
// return logintoken, protocol.NewErrWithMessage("10201")
// }
// companyData, err = models.GetCompanyByUCenter(uclientReturn.Data.CompanyId)
// if err != nil {
// log.Error("获取company数据失败:%s", err)
// return logintoken, protocol.NewErrWithMessage("10211")
// }
// if companyData.Enable == models.COMPANY_ENABLE_NO {
// log.Error("公司未启用机会模块")
// return logintoken, protocol.NewErrWithMessage("10212")
// }
// ucompany, err := models.GetUserCompanyBy(userdata.Id, companyData.Id)
// if err != nil {
// log.Error("获取user_company失败;%s", err)
// return logintoken, protocol.NewErrWithMessage("10202")
// }
ucompany, err := models.GetUserCompanyById(uclientReturn.Data.Muid)
if err != nil {
log.Error("更新用户user_company数据失败:%s", err)
log.Error("获取user_company失败;%s", err)
return logintoken, protocol.NewErrWithMessage("10202")
}
InitPermission(ucompany.Id, userdata.Id)
logintoken, _ = GenerateAuthToken(ucompany.UserId, ucompany.CompanyId, ucompany.Id)
//更新用户数据
//用户数据的更新 交由数据同步的接口处理
// var userdata *models.User
// userdata.Id = ucompany.UserId
// userdata.Accid = uclientReturn.Data.Accid
// userdata.Icon = uclientReturn.Data.Avatar
// userdata.ImToken = uclientReturn.Data.Imtoken
// userdata.NickName = uclientReturn.Data.NickName
// userdata.CsAccount = uclientReturn.Data.CustomerAccount
// userdata.LastLoginTime = time.Now()
// err = models.UpdateUserById(userdata, []string{"Accid", "Icon", "ImToken", "NickName", "CsAccount", "LastLoginTime"})
// if err != nil {
// log.Error("更新用户user数据失败:%s", err)
// }
// ucompany.NickName = uclientReturn.Data.NickName
// err = models.UpdateUserCompanyById(ucompany, []string{"NickName"})
// if err != nil {
// log.Error("更新用户user_company数据失败:%s", err)
// }
InitPermission(ucompany.Id, ucompany.UserId)
return logintoken, err
}
... ...
... ... @@ -50,7 +50,7 @@ func (r RequesLogin) Valid() error {
type ResponseLogin struct {
CommResponse
Data struct {
Id int64 `json:"id"`
Id int64 `json:"id"` //统一用户中心的id
Phone string `json:"phone"`
NickName string `json:"nickname"` //昵称
Avatar string `json:"avatar"` //头像
... ... @@ -58,6 +58,7 @@ type ResponseLogin struct {
Accid int64 `json:"accid"` //网易云id
CustomerAccount int64 `json:"customerAccount"` //客服id
CompanyId int64 `json:"companyId"` //总后台的公司id
Muid int64 `json:"muid"` //企业平台的用户id,对应本系统中user_company表的id
} `json:"data"`
}
... ...