Browse Source

jwt异地登陆bug修复

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

4
server/middleware/jwt.go

@ -26,7 +26,7 @@ func JWTAuth() gin.HandlerFunc {
c.Abort() c.Abort()
return return
} }
if service.IsBlacklist(token,modelToken) {
if service.IsBlacklist(token, &modelToken) {
response.Result(response.ERROR, gin.H{ response.Result(response.ERROR, gin.H{
"reload": true, "reload": true,
}, "您的帐户异地登陆或令牌失效", c) }, "您的帐户异地登陆或令牌失效", c)
@ -66,8 +66,6 @@ var (
TokenInvalid error = errors.New("Couldn't handle this token:") TokenInvalid error = errors.New("Couldn't handle this token:")
) )
func NewJWT() *JWT { func NewJWT() *JWT {
return &JWT{ return &JWT{
[]byte(global.GVA_CONFIG.JWT.SigningKey), []byte(global.GVA_CONFIG.JWT.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 ) // @auth (2020/04/05 20:22 )
// @param newPassword string // @param newPassword string
// @return err error // @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() isNotFound := global.GVA_DB.Where("jwt = ?", Jwt).First(j).RecordNotFound()
return !isNotFound 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() err = global.GVA_REDIS.Set(userName, j.Jwt, 1000*1000*1000*60*60*24*7).Err()
return err return err
} }
Loading…
Cancel
Save