From 35eaa483134dbe7f48f1b8322de1a41af2a891dc Mon Sep 17 00:00:00 2001 From: QM303176530 <303176530@qq.com> Date: Wed, 8 Apr 2020 20:15:13 +0800 Subject: [PATCH] =?UTF-8?q?jwt=E5=BC=82=E5=9C=B0=E7=99=BB=E9=99=86bug?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- server/middleware/jwt.go | 6 ++---- server/service/jwt_black_list.go | 3 +-- 2 files changed, 3 insertions(+), 6 deletions(-) diff --git a/server/middleware/jwt.go b/server/middleware/jwt.go index cd671d44..cfc9d0bb 100644 --- a/server/middleware/jwt.go +++ b/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) } diff --git a/server/service/jwt_black_list.go b/server/service/jwt_black_list.go index 888d5b61..eab1b55f 100644 --- a/server/service/jwt_black_list.go +++ b/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 } -