This commit is contained in:
wucongxing8150 2024-10-18 14:15:55 +08:00
parent 9e6beb2f2c
commit 7198cdecdb
2 changed files with 22 additions and 2 deletions

View File

@ -2,8 +2,10 @@ package middlewares
import (
"github.com/gin-gonic/gin"
"net/http"
"vote-admin-api/api/dao"
"vote-admin-api/api/responses"
"vote-admin-api/consts"
)
// Auth Auth认证
@ -21,13 +23,21 @@ func Auth() gin.HandlerFunc {
userDao := dao.UserDao{}
user, err := userDao.GetUserById(userId)
if err != nil || user == nil {
responses.FailWithMessage("用户数据错误", c)
c.JSON(http.StatusUnauthorized, gin.H{
"message": "用户数据错误",
"code": consts.UserStatusError,
"data": "",
})
c.Abort()
return
}
if user.UserStatus == 2 {
responses.FailWithMessage("用户已禁用", c)
c.JSON(http.StatusUnauthorized, gin.H{
"message": "用户已禁用",
"code": consts.UserStatusError,
"data": "",
})
c.Abort()
return
}

View File

@ -26,6 +26,16 @@ func Jwt() gin.HandlerFunc {
// 去除Bearer
authorization = authorization[7:] // 截取字符
if authorization == "" {
c.JSON(http.StatusOK, gin.H{
"message": "token错误/过期",
"code": consts.TokenError,
"data": "",
})
c.Abort()
return
}
// 检测是否存在黑名单
res, _ := global.Redis.Get(c, "jwt_black_"+authorization).Result()