增加令牌自动续期功能

This commit is contained in:
pixel
2020-08-17 14:04:02 +08:00
parent 9679616935
commit 0239f7b97c
7 changed files with 62 additions and 55 deletions
+7 -4
View File
@@ -3,6 +3,7 @@ package service
import (
"gin-vue-admin/global"
"gin-vue-admin/model"
"time"
)
// @title JsonInBlacklist
@@ -23,8 +24,8 @@ func JsonInBlacklist(jwtList model.JwtBlacklist) (err error) {
// @param jwtList model.JwtBlacklist
// @return err error
func IsBlacklist(jwt string, jwtList model.JwtBlacklist) bool {
isNotFound := global.GVA_DB.Where("jwt = ?", jwt).First(&jwtList).RecordNotFound()
func IsBlacklist(jwt string) bool {
isNotFound := global.GVA_DB.Where("jwt = ?", jwt).First(&model.JwtBlacklist{}).RecordNotFound()
return !isNotFound
}
@@ -47,7 +48,9 @@ func GetRedisJWT(userName string) (err error, redisJWT string) {
// @param userName string
// @return err error
func SetRedisJWT(jwtList model.JwtBlacklist, userName string) (err error) {
err = global.GVA_REDIS.Set(userName, jwtList.Jwt, 1000*1000*1000*60*60*24*7).Err()
func SetRedisJWT(jwt string, userName string) (err error) {
// 此处过期时间等于jwt过期时间
timer := 60*60*24*7*time.Second
err = global.GVA_REDIS.Set(userName, jwt, timer).Err()
return err
}