...
|
...
|
@@ -40,7 +40,7 @@ func assertImplement() { |
|
|
var (
|
|
|
//服务
|
|
|
sms s_sms.ISmsService = &s_sms.YunPianSmsService{}
|
|
|
|
|
|
ConfigRepository repository.IConfigRepository = &repository.ConfigRepository{}
|
|
|
//仓储
|
|
|
UserRepository repository.IUserRepository = &repository.UserRepository{}
|
|
|
)
|
...
|
...
|
@@ -87,7 +87,9 @@ Success: |
|
|
if userInfo.Auth == "" {
|
|
|
userInfo.Auth = uid.NewV1().StringNoDash()
|
|
|
}
|
|
|
if err = models.UpdateUserInfoById(userInfo); err != nil {
|
|
|
//TODO:更新
|
|
|
userInfo.AuthExp = time.Now().Add(time.Second*protocol.TokenExpire)
|
|
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.LoginResponse{AuthCode: userInfo.Auth}
|
...
|
...
|
@@ -106,19 +108,20 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
|
|
var (
|
|
|
userInfo *models.UserInfo
|
|
|
)
|
|
|
_, err = models.GetCfgClient(request.ClientId, request.ClientSecret)
|
|
|
_, err = ConfigRepository.GetCfgClient(request.ClientId, request.ClientSecret)
|
|
|
if err != nil {
|
|
|
common.NewError(101, err)
|
|
|
err = common.NewError(101, err)
|
|
|
return
|
|
|
}
|
|
|
userInfo, err = models.GetUserInfoByAuthCode(request.AuthCode)
|
|
|
userInfo, err = UserRepository.GetUserInfoByAuthCode(request.AuthCode)
|
|
|
if err != nil {
|
|
|
common.NewError(4139, err)
|
|
|
err = common.NewError(4139, err)
|
|
|
return
|
|
|
}
|
|
|
userInfo.AccessToken = uid.NewV1().StringNoDash()
|
|
|
userInfo.RefreshToken = uid.NewV1().StringNoDash()
|
|
|
if err = models.UpdateUserInfoById(userInfo); err != nil {
|
|
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
|
|
log.Error(err)
|
|
|
return
|
|
|
}
|
|
|
//valid token
|
...
|
...
|
@@ -134,25 +137,24 @@ func (s *AuthService) AccessToken(request *protocol.AccessTokenRequest) (rsp *pr |
|
|
func (s *AuthService) RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
|
|
|
var (
|
|
|
userInfo *models.UserInfo
|
|
|
newAccess *protocol.Access
|
|
|
)
|
|
|
_, err = models.GetCfgClient(request.ClientId, request.ClientSecret)
|
|
|
_, err = ConfigRepository.GetCfgClient(request.ClientId, request.ClientSecret)
|
|
|
if err != nil {
|
|
|
common.NewError(101, err)
|
|
|
return
|
|
|
}
|
|
|
userInfo, err = models.GetUserInfoByAuthCode(request.RefreshToken)
|
|
|
userInfo, err = UserRepository.GetUserInfoByRefreshToken(request.RefreshToken)
|
|
|
if err != nil {
|
|
|
common.NewError(4139, err)
|
|
|
return
|
|
|
}
|
|
|
userInfo.AccessToken = uid.NewV1().StringNoDash()
|
|
|
if err = models.UpdateUserInfoById(userInfo); err != nil {
|
|
|
if err = UserRepository.UpdateUserInfoById(userInfo); err != nil {
|
|
|
return
|
|
|
}
|
|
|
rsp = &protocol.RefreshTokenResponse{
|
|
|
AccessToken: newAccess.AccessToken,
|
|
|
RefreshToken: newAccess.RefreshToken,
|
|
|
AccessToken: userInfo.AccessToken,
|
|
|
RefreshToken: userInfo.RefreshToken,
|
|
|
ExpiresIn: protocol.TokenExpire,
|
|
|
}
|
|
|
return
|
...
|
...
|
|