feat: 修改jwt逻辑,登出黑名单处理
This commit is contained in:
+13
-3
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user