...
|
...
|
@@ -66,7 +66,7 @@ func Login(header *protocol.RequestHeader, request *protocol.LoginRequest) (rsp |
|
|
err = protocol.NewCustomMessage(1, "登录方式不支持!")
|
|
|
break
|
|
|
}
|
|
|
rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, protocol.AuthCodeExpire*time.Second)
|
|
|
rsp.AuthCode, _ = utils.GenerateToken(partnerInfo.Id, request.Phone, protocol.AuthCodeExpire*time.Second)
|
|
|
|
|
|
if err = InitOrUpdateUserIMInfo(partnerInfo, transactionContext); err != nil {
|
|
|
log.Error(err)
|
...
|
...
|
@@ -105,8 +105,8 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke |
|
|
err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt authCode (%v) valid", request.AuthCode))
|
|
|
return
|
|
|
}
|
|
|
rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second)
|
|
|
rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second)
|
|
|
rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.TokenExpire*time.Second)
|
|
|
rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.RefreshTokenExipre*time.Second)
|
|
|
rsp.ExpiresIn = protocol.TokenExpire
|
|
|
|
|
|
//auth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId),
|
...
|
...
|
@@ -121,8 +121,22 @@ func AccessToken(request *protocol.AccessTokenRequest) (rsp *protocol.AccessToke |
|
|
|
|
|
func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshTokenResponse, err error) {
|
|
|
var (
|
|
|
claim *utils.UserTokenClaims
|
|
|
claim *utils.UserTokenClaims
|
|
|
transactionContext, _ = factory.CreateTransactionContext(nil)
|
|
|
PartnerInfoService, _ = factory.CreatePartnerInfoRepositoryIn(transactionContext)
|
|
|
PartnerSubAccountRepository, _ = factory.CreatePartnerSubAccountRepository(transactionContext)
|
|
|
|
|
|
partnerInfo *domain.PartnerInfo
|
|
|
partnerSubAccount *domain.PartnerSubAccount
|
|
|
)
|
|
|
|
|
|
if err = transactionContext.StartTransaction(); err != nil {
|
|
|
return nil, err
|
|
|
}
|
|
|
defer func() {
|
|
|
transactionContext.RollbackTransaction()
|
|
|
}()
|
|
|
|
|
|
rsp = &protocol.RefreshTokenResponse{}
|
|
|
if claim, err = utils.ParseJWTToken(request.RefreshToken); err != nil {
|
|
|
err = protocol.NewErrWithMessage(4140, err)
|
...
|
...
|
@@ -132,14 +146,27 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT |
|
|
err = protocol.NewErrWithMessage(1, fmt.Errorf("jwt refrshToken (%v) valid", request.RefreshToken))
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//验证用户有效
|
|
|
var e error
|
|
|
if partnerSubAccount, e = PartnerSubAccountRepository.FindOne(map[string]interface{}{"account": claim.Phone}); e == nil {
|
|
|
partnerInfo, e = PartnerInfoService.FindOne(map[string]interface{}{"id": partnerSubAccount.PartnerId})
|
|
|
} else {
|
|
|
partnerInfo, e = PartnerInfoService.FindOne(map[string]interface{}{"account": claim.Phone})
|
|
|
}
|
|
|
if e != nil || partnerInfo == nil || !partnerInfo.IsEnable() || partnerInfo.Id != claim.UserId {
|
|
|
err = protocol.NewErrWithMessage(4140) //账号禁用
|
|
|
return
|
|
|
}
|
|
|
|
|
|
//oldAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId))
|
|
|
//if err = oldAuth.Check(userAuth.NewOptions(userAuth.WithRefreshToken(request.RefreshToken))); err != nil {
|
|
|
// log.Error(err)
|
|
|
// err = protocol.NewErrWithMessage(4140, err)
|
|
|
// return
|
|
|
//}
|
|
|
rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, protocol.TokenExpire*time.Second)
|
|
|
rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, protocol.RefreshTokenExipre*time.Second)
|
|
|
rsp.AccessToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.TokenExpire*time.Second)
|
|
|
rsp.RefreshToken, _ = utils.GenerateToken(claim.UserId, claim.Phone, protocol.RefreshTokenExipre*time.Second)
|
|
|
rsp.ExpiresIn = protocol.TokenExpire
|
|
|
|
|
|
//newAuth := userAuth.NewRedisUserAuth(userAuth.WithUserId(claim.UserId),
|
...
|
...
|
@@ -149,6 +176,7 @@ func RefreshToken(request *protocol.RefreshTokenRequest) (rsp *protocol.RefreshT |
|
|
// log.Error(err)
|
|
|
// return
|
|
|
//}
|
|
|
err = transactionContext.CommitTransaction()
|
|
|
return
|
|
|
}
|
|
|
|
...
|
...
|
|