feat: 修改jwt逻辑,登出黑名单处理

This commit is contained in:
Blizzard
2025-09-15 21:00:39 +08:00
parent 9be75d53fe
commit 6beb915adf
9 changed files with 74 additions and 64 deletions
+13 -3
View File
@@ -6,7 +6,7 @@ import (
"sundynix-go/model/system"
systemReq "sundynix-go/model/system/request"
systemRes "sundynix-go/model/system/response"
"sundynix-go/utils"
"sundynix-go/utils/jwt"
"github.com/gin-gonic/gin"
"github.com/mojocn/base64Captcha"
@@ -41,7 +41,17 @@ func (a *AuthApi) Login(c *gin.Context) {
// 登出
func (a *AuthApi) Logout(c *gin.Context) {
utils.ClearToken(c)
token := jwt.GetToken(c)
userId := jwt.GetUserId(c)
err := jwtService.PutBlacklist(userId, token)
if err != nil {
global.Logger.Error("登出失败!", zap.Error(err))
response.FailWithMsg("登出失败", c)
return
}
jwt.ClearToken(c)
response.OkWithMsg("登出成功", c)
}
// Captcha api 生成验证码
@@ -69,7 +79,7 @@ func (u *AuthApi) Captcha(c *gin.Context) {
}
func (a *AuthApi) GetToken(c *gin.Context, user system.User) {
token, claims, err := utils.GetLoginToken(&user)
token, claims, err := jwt.GetLoginToken(&user)
if err != nil {
global.Logger.Error("GetToken err", zap.Error(err))
response.FailWithMsg("GetToken err", c)
+1
View File
@@ -11,6 +11,7 @@ type ApiGroup struct {
}
var (
jwtService = service.ServiceGroupApp.SystemServiceGroup.JwtService
userService = service.ServiceGroupApp.SystemServiceGroup.UserService
clientService = service.ServiceGroupApp.SystemServiceGroup.ClientService
roleService = service.ServiceGroupApp.SystemServiceGroup.RoleService
+2 -2
View File
@@ -5,7 +5,7 @@ import (
"sundynix-go/model/commom/response"
"sundynix-go/model/system"
systemReq "sundynix-go/model/system/request"
"sundynix-go/utils"
"sundynix-go/utils/jwt"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
@@ -89,7 +89,7 @@ func (m *MenuApi) GetUserMenuTree(c *gin.Context) {
}
func (m *MenuApi) Route(c *gin.Context) {
userId := utils.GetUserId(c)
userId := jwt.GetUserId(c)
routes, err := menuService.GetUserRoutes(userId)
if err != nil {
global.Logger.Error("获取用户菜单失败!", zap.Error(err))