Browse Source

jwt异地登陆bug修复

main
QM303176530 5 years ago
parent
commit
35eaa48313
  1. 6
      server/middleware/jwt.go
  2. 3
      server/service/jwt_black_list.go

6
server/middleware/jwt.go

@ -26,7 +26,7 @@ func JWTAuth() gin.HandlerFunc {
c.Abort()
return
}
if service.IsBlacklist(token,modelToken) {
if service.IsBlacklist(token, &modelToken) {
response.Result(response.ERROR, gin.H{
"reload": true,
}, "您的帐户异地登陆或令牌失效", c)
@ -66,8 +66,6 @@ var (
TokenInvalid error = errors.New("Couldn't handle this token:")
)
func NewJWT() *JWT {
return &JWT{
[]byte(global.GVA_CONFIG.JWT.SigningKey),
@ -75,7 +73,7 @@ func NewJWT() *JWT {
}
//创建一个token
func (j *JWT) CreateToken(claims request. CustomClaims) (string, error) {
func (j *JWT) CreateToken(claims request.CustomClaims) (string, error) {
token := jwt.NewWithClaims(jwt.SigningMethodHS256, claims)
return token.SignedString(j.SigningKey)
}

3
server/service/jwt_black_list.go

@ -19,7 +19,7 @@ func JsonInBlacklist(j *model.JwtBlacklist) (err error) {
// @auth (2020/04/05 20:22 )
// @param newPassword string
// @return err error
func IsBlacklist(Jwt string, j model.JwtBlacklist) bool {
func IsBlacklist(Jwt string, j *model.JwtBlacklist) bool {
isNotFound := global.GVA_DB.Where("jwt = ?", Jwt).First(j).RecordNotFound()
return !isNotFound
}
@ -43,4 +43,3 @@ func SetRedisJWT(j model.JwtBlacklist, userName string) (err error) {
err = global.GVA_REDIS.Set(userName, j.Jwt, 1000*1000*1000*60*60*24*7).Err()
return err
}
Loading…
Cancel
Save