...
|
...
|
@@ -134,7 +134,7 @@ func ChangeLoginToken(userid, companyid int64) (protocol.LoginAuthToken, error) |
|
|
log.Debug("无效公司")
|
|
|
return logintoken, protocol.NewErrWithMessage("10027")
|
|
|
}
|
|
|
logintoken, err = GenerateAuthToken(userid, companydata.Id)
|
|
|
logintoken, err = GenerateAuthToken(userid, companydata.Id, usercompany.Id)
|
|
|
if err != nil {
|
|
|
log.Error("GenerateAuthToken err:%s", err)
|
|
|
return logintoken, protocol.NewErrWithMessage("1")
|
...
|
...
|
@@ -142,38 +142,38 @@ func ChangeLoginToken(userid, companyid int64) (protocol.LoginAuthToken, error) |
|
|
return logintoken, nil
|
|
|
}
|
|
|
|
|
|
func RefreshLoginToken(refreshtoken string) (protocol.LoginAuthToken, error) {
|
|
|
var (
|
|
|
logintoken protocol.LoginAuthToken
|
|
|
mtoken *MyToken
|
|
|
err error
|
|
|
storetoken redisdata.RedisLoginToken
|
|
|
)
|
|
|
mtoken, err = ValidJWTToken(refreshtoken)
|
|
|
if err != nil {
|
|
|
log.Debug("token失效 err:%s", err)
|
|
|
return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
}
|
|
|
storetoken, err = redisdata.GetLoginToken(mtoken.UID, mtoken.CompanyID)
|
|
|
if err != nil {
|
|
|
log.Error("redis err:%s", err)
|
|
|
return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
}
|
|
|
if storetoken.RefreshToken != refreshtoken {
|
|
|
return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
}
|
|
|
logintoken, _ = GenerateAuthToken(mtoken.UID, mtoken.CompanyID)
|
|
|
return logintoken, nil
|
|
|
}
|
|
|
// func RefreshLoginToken(refreshtoken string) (protocol.LoginAuthToken, error) {
|
|
|
// var (
|
|
|
// logintoken protocol.LoginAuthToken
|
|
|
// mtoken *MyToken
|
|
|
// err error
|
|
|
// storetoken redisdata.RedisLoginToken
|
|
|
// )
|
|
|
// mtoken, err = ValidJWTToken(refreshtoken)
|
|
|
// if err != nil {
|
|
|
// log.Debug("token失效 err:%s", err)
|
|
|
// return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
// }
|
|
|
// storetoken, err = redisdata.GetLoginToken(mtoken.UID, mtoken.CompanyID)
|
|
|
// if err != nil {
|
|
|
// log.Error("redis err:%s", err)
|
|
|
// return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
// }
|
|
|
// if storetoken.RefreshToken != refreshtoken {
|
|
|
// return logintoken, protocol.NewErrWithMessage("10024")
|
|
|
// }
|
|
|
// logintoken, _ = GenerateAuthToken(mtoken.UID, mtoken.CompanyID)
|
|
|
// return logintoken, nil
|
|
|
// }
|
|
|
|
|
|
func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, error) {
|
|
|
var (
|
|
|
err error
|
|
|
logintoken protocol.LoginAuthToken
|
|
|
|
|
|
companys []companybase
|
|
|
companyid int64
|
|
|
userdata *models.User
|
|
|
err error
|
|
|
logintoken protocol.LoginAuthToken
|
|
|
usercompanyid int64
|
|
|
companys []companybase
|
|
|
companyid int64
|
|
|
userdata *models.User
|
|
|
)
|
|
|
var uclientReturn *ucenter.ResponseLogin
|
|
|
uclientReturn, err = ucenter.RequestUCenterLogin(account, password)
|
...
|
...
|
@@ -204,11 +204,28 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
//获取上一次登录的公司
|
|
|
uAuth, err := models.GetUserAuthByUser(userdata.Id)
|
|
|
if err == nil {
|
|
|
companyid = uAuth.CurrentCompanyId
|
|
|
has := false
|
|
|
for _, v := range companys {
|
|
|
if v.Id == uAuth.CurrentCompanyId {
|
|
|
companyid = uAuth.CurrentCompanyId
|
|
|
has = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !has {
|
|
|
companyid = companys[0].Id
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
companyid = companys[0].Id
|
|
|
}
|
|
|
|
|
|
ucompany, err := models.GetUserCompanyBy(userdata.Id, companyid)
|
|
|
if err != nil {
|
|
|
log.Error("获取user_company失败;%s", err)
|
|
|
return logintoken, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
usercompanyid = ucompany.Id
|
|
|
logintoken, _ = GenerateAuthToken(userdata.Id, companyid, usercompanyid)
|
|
|
//更新用户数据
|
|
|
userdata.Accid = uclientReturn.Data.Accid
|
|
|
userdata.Icon = uclientReturn.Data.Avatar
|
...
|
...
|
@@ -220,7 +237,6 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
if err != nil {
|
|
|
log.Error("更新用户数据失败:%s", err)
|
|
|
}
|
|
|
logintoken, _ = GenerateAuthToken(userdata.Id, companyid)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
...
|
...
|
@@ -329,11 +345,12 @@ func GetUserHasMenu(userid, companyid int64) ([]protocol.PermissionItem, error) |
|
|
|
|
|
func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, error) {
|
|
|
var (
|
|
|
err error
|
|
|
logintoken protocol.LoginAuthToken
|
|
|
companys []companybase
|
|
|
companyid int64
|
|
|
userdata *models.User
|
|
|
err error
|
|
|
logintoken protocol.LoginAuthToken
|
|
|
companys []companybase
|
|
|
companyid int64
|
|
|
usercompanyid int64
|
|
|
userdata *models.User
|
|
|
)
|
|
|
var uclientReturn *ucenter.ResponseLoginSms
|
|
|
uclientReturn, err = ucenter.RequestUCenterLoginSms(phone, code)
|
...
|
...
|
@@ -364,11 +381,27 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err |
|
|
//获取上一次登录的公司
|
|
|
uAuth, err := models.GetUserAuthByUser(userdata.Id)
|
|
|
if err == nil {
|
|
|
companyid = uAuth.CurrentCompanyId
|
|
|
has := false
|
|
|
for _, v := range companys {
|
|
|
if v.Id == uAuth.CurrentCompanyId {
|
|
|
companyid = uAuth.CurrentCompanyId
|
|
|
has = true
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
if !has {
|
|
|
companyid = companys[0].Id
|
|
|
}
|
|
|
} else {
|
|
|
companyid = companys[0].Id
|
|
|
}
|
|
|
|
|
|
ucompany, err := models.GetUserCompanyBy(userdata.Id, companyid)
|
|
|
if err != nil {
|
|
|
log.Error("获取user_company失败;%s", err)
|
|
|
return logintoken, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
usercompanyid = ucompany.Id
|
|
|
logintoken, _ = GenerateAuthToken(userdata.Id, companyid, usercompanyid)
|
|
|
//更新用户数据
|
|
|
userdata.Accid = uclientReturn.Data.CsAccountID
|
|
|
userdata.Icon = uclientReturn.Data.Image.Path
|
...
|
...
|
@@ -379,7 +412,6 @@ func LoginAuthBySmsCode(phone string, code string) (protocol.LoginAuthToken, err |
|
|
if err != nil {
|
|
|
log.Error("更新用户数据失败:%s", err)
|
|
|
}
|
|
|
logintoken, _ = GenerateAuthToken(userdata.Id, companyid)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
...
|
...
|
|