...
|
...
|
@@ -3,11 +3,13 @@ package auth |
|
|
import (
|
|
|
"crypto/sha1"
|
|
|
"encoding/hex"
|
|
|
"encoding/json"
|
|
|
"fmt"
|
|
|
"io"
|
|
|
"oppmg/common/log"
|
|
|
"oppmg/models"
|
|
|
"oppmg/protocol"
|
|
|
"oppmg/services/ucenter"
|
|
|
"oppmg/storage/redisdata"
|
|
|
"oppmg/utils"
|
|
|
"strings"
|
...
|
...
|
@@ -79,7 +81,7 @@ func ResetLoginToken(loginToken protocol.LoginAuthToken) error { |
|
|
uAuth.RefreshToken = loginToken.RefreshToken
|
|
|
uAuth.RefreshTokenExp = time.Unix(loginToken.RefreshExpires, 0)
|
|
|
uAuth.UpdateAt = nowTime
|
|
|
upCol := []string{"CurrentCompanyId", "AccessToken", "RefreshToken", "RefreshTokenExp", "UpdateAt"}
|
|
|
upCol := []string{"CurrentCompanyId", "AccessTokenExp", "RefreshTokenExp", "AccessToken", "RefreshToken", "RefreshTokenExp", "UpdateAt"}
|
|
|
if err = models.UpdateUserAuthById(uAuth, upCol); err != nil {
|
|
|
e := fmt.Errorf("UpdateUserAuthById err:%s", err)
|
|
|
log.Error(e.Error())
|
...
|
...
|
@@ -189,7 +191,7 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
}
|
|
|
if ok := userdata.IsEnable(); !ok {
|
|
|
log.Debug("userdata.IsEnable()==false")
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
return logintoken, protocol.NewErrWithMessage("10022")
|
|
|
}
|
|
|
if companys, err = getUserCompanyReal(userdata.Id); err != nil {
|
|
|
log.Error("getUserCompanyReal err:%s", err)
|
...
|
...
|
@@ -197,33 +199,55 @@ func LoginAuthByUCenter(account, password string) (protocol.LoginAuthToken, erro |
|
|
}
|
|
|
if len(companys) == 0 {
|
|
|
log.Debug("no company")
|
|
|
return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
return logintoken, protocol.NewErrWithMessage("10022")
|
|
|
}
|
|
|
companyid = companys[0].Id
|
|
|
// var uclientReturn ucenter.ResponseLogin
|
|
|
// param := ucenter.RequesLogin{
|
|
|
// Phone: account,
|
|
|
// Password: password,
|
|
|
// }
|
|
|
// uclient := ucenter.NewUCenterClient()
|
|
|
// btBody, err := uclient.Call(param)
|
|
|
// var uclientReturn *ucenter.ResponseLogin
|
|
|
// uclientReturn, err = requestUCenterLogin(account, password)
|
|
|
// if err != nil {
|
|
|
// log.Error("统一用户中心请求失败 err:%s", err)
|
|
|
// return logintoken, protocol.NewErrWithMessage("1")
|
|
|
// return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
// }
|
|
|
// err = json.Unmarshal(btBody, &uclientReturn)
|
|
|
// //更新用户数据
|
|
|
// _ = uclientReturn
|
|
|
// 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("解析统一用户中心响应失败 err:%s", err)
|
|
|
// return logintoken, protocol.NewErrWithMessage("1")
|
|
|
// }
|
|
|
// if !(uclientReturn.Code == ucenter.ResponseCode0 &&
|
|
|
// uclientReturn.Msg == ucenter.ResponseMsgOk) {
|
|
|
// return logintoken, protocol.NewErrWithMessage("10021")
|
|
|
// log.Error("更新用户数据失败:%s", err)
|
|
|
// }
|
|
|
logintoken, _ = GenerateAuthToken(userdata.Id, companyid)
|
|
|
return logintoken, err
|
|
|
}
|
|
|
|
|
|
func requestUCenterLogin(account, password string) (*ucenter.ResponseLogin, error) {
|
|
|
var uclientReturn *ucenter.ResponseLogin
|
|
|
param := ucenter.RequesLogin{
|
|
|
Type: 1,
|
|
|
Phone: account,
|
|
|
Password: password,
|
|
|
}
|
|
|
uclient := ucenter.NewUCenterClient()
|
|
|
btBody, err := uclient.Call(param)
|
|
|
if err != nil {
|
|
|
log.Error("统一用户中心请求失败 err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
err = json.Unmarshal(btBody, &uclientReturn)
|
|
|
if err != nil {
|
|
|
log.Error("解析统一用户中心响应失败 err:%s", err)
|
|
|
return nil, protocol.NewErrWithMessage("1")
|
|
|
}
|
|
|
if !(uclientReturn.Code == ucenter.ResponseCode0 &&
|
|
|
uclientReturn.Msg == ucenter.ResponseMsgOk) {
|
|
|
return nil, protocol.NewErrWithMessage("10021")
|
|
|
}
|
|
|
return uclientReturn, nil
|
|
|
}
|
|
|
|
|
|
type companybase struct {
|
|
|
Id int64 `orm:"column(id)"`
|
|
|
Name string `orm:"coumn(name)"`
|
...
|
...
|
|