作者 yangfu

修改登录

... ... @@ -137,6 +137,10 @@ func (this *UserController) SwitchCompany() {
return
}
header := controllers.GetRequestHeader(this.Ctx)
if beego.BConfig.RunMode == "prod" || beego.BConfig.RunMode == "test" {
msg = protocol.NewReturnResponse(user.SwitchCompanyV3(header, request))
return
}
msg = protocol.NewReturnResponse(user.SwitchCompany(header, request))
}
... ...
... ... @@ -87,7 +87,7 @@ func LoginV3(header *protocol.RequestHeader, request *protocol.LoginRequest) (rs
}
}
if !hasAuth {
err = protocol.NewErrWithMessage(2002, err) //账号不存在
err = protocol.NewErrWithMessage(4140, err) //账号不存在
return
}
}
... ...
... ... @@ -238,7 +238,7 @@ func UserCompanys(header *protocol.RequestHeader, request *protocol.UserCompanys
}
//切换公司
func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
func SwitchCompanyV3(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
var (
userCompany *models.UserCompany
auth *models.UserAuth
... ... @@ -276,6 +276,40 @@ func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompa
return
}
func SwitchCompany(header *protocol.RequestHeader, request *protocol.SwitchCompanyRequest) (rsp *protocol.SwitchCompanyResponse, err error) {
var (
userCompany *models.UserCompany
auth *models.UserAuth
)
if userCompany, err = models.GetUserCompanyByUserId(header.Uid, int64(request.CompanyId)); err != nil {
log.Error(err)
err = protocol.NewErrWithMessage(4201) //找不到这家公司
return
}
if auth, err = models.GetUserAuthByUserId(header.Uid, protocol.DeviceType); err != nil {
log.Error(err)
return
}
if auth.CurrentCompanyId == request.CompanyId {
log.Error(fmt.Sprintf("uid:%v 当前公司已经是:%v", header.Uid, request.CompanyId))
//return
} else {
auth.AuthCode = uid.NewV1().StringNoDash()
auth.AuthCodeExp = time.Now().Add(time.Second * protocol.TokenExpire)
if err = utils.UpdateTableByMap(&models.UserAuth{Id: auth.Id}, map[string]interface{}{
"CurrentCompanyId": userCompany.CompanyId, "CurrentUserCompanyId": userCompany.Id, "AuthCode": auth.AuthCode, "AuthCodeExp": auth.AuthCodeExp},
); err != nil {
log.Error(err)
return
}
header.CompanyId = userCompany.CompanyId
header.UserId = userCompany.Id
}
rsp = &protocol.SwitchCompanyResponse{}
rsp.AuthCode = auth.AuthCode
return
}
//用户信息
func UserInfo(header *protocol.RequestHeader, request *protocol.UserInfoRequest) (rsp *protocol.UserInfoResponse, err error) {
var (
... ...