🎨优化
This commit is contained in:
parent
9af89ee41f
commit
3e1d3d63d0
@ -68,7 +68,10 @@ func (JwtComponent) GenerateToken(userId, secret string, times ...time.Time) (to
|
|||||||
return "", nil, errors.New("生成token失败")
|
return "", nil, errors.New("生成token失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
client.Redis.Set(context.Background(), fmt.Sprintf("%s:%s", constant.UserToken, userId), token, 7*time.Hour)
|
client.Redis.Set(context.Background(),
|
||||||
|
fmt.Sprintf("%s:%s", constant.UserToken, userId),
|
||||||
|
token,
|
||||||
|
time.Duration(expireTime.Sub(time.Now()).Abs().Seconds())*time.Second)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
package constant
|
package constant
|
||||||
|
|
||||||
const (
|
const (
|
||||||
Captcha = "captcha:"
|
Captcha = "captcha"
|
||||||
UserToken = "token:"
|
UserToken = "token"
|
||||||
)
|
)
|
||||||
|
@ -65,7 +65,7 @@ func Authorization() gin.HandlerFunc {
|
|||||||
|
|
||||||
// 生成一个新token
|
// 生成一个新token
|
||||||
secret := component.JWT().GenerateSecret(user.Password, uuid.NewString(), time.Now().Local().String())
|
secret := component.JWT().GenerateSecret(user.Password, uuid.NewString(), time.Now().Local().String())
|
||||||
tokenStr, _, err := component.JWT().GenerateToken(user.Id, secret, userClaims.ExpiresAt.Time, userClaims.IssuedAt.Time)
|
tokenStr, _, err := component.JWT().GenerateToken(user.Id, secret, userClaims.ExpiresAt.Time, time.Now().Local())
|
||||||
if err != nil {
|
if err != nil {
|
||||||
response.R(c).AuthorizationFailed("校验失败")
|
response.R(c).AuthorizationFailed("校验失败")
|
||||||
c.Abort()
|
c.Abort()
|
||||||
|
Loading…
Reference in New Issue
Block a user