修改拦截请求

This commit is contained in:
junleea 2025-06-02 17:58:12 +08:00
parent 892e080d6a
commit d6bf91c9fd
1 changed files with 4 additions and 16 deletions

20
main.go
View File

@ -124,12 +124,7 @@ func JWTAuthMiddleware() gin.HandlerFunc {
if proto.Config.TOKEN_USE_REDIS { if proto.Config.TOKEN_USE_REDIS {
redisToken := worker.GetRedis(tokenString) redisToken := worker.GetRedis(tokenString)
if redisToken == "" { if redisToken == "" {
c.AbortWithStatus(200) c.AbortWithStatusJSON(http.StatusOK, gin.H{"message": "NOT_LOGIN", "error": "server token is empty", "code": proto.TokenIsNull})
c.JSON(200, gin.H{
"message": "NOT_LOGIN",
"error": "server token is empty",
"code": proto.TokenIsNull,
})
return return
} }
} }
@ -141,12 +136,7 @@ func JWTAuthMiddleware() gin.HandlerFunc {
sId = c.Query("super_id") sId = c.Query("super_id")
} }
if sId == "" { if sId == "" {
c.AbortWithStatus(200) c.AbortWithStatusJSON(http.StatusOK, gin.H{"message": "unauthorized", "error": "super_id is empty", "code": proto.TokenIsNull})
c.JSON(200, gin.H{
"message": "NOT_LOGIN",
"error": "super_id is empty",
"code": proto.TokenIsNull,
})
return return
} }
id, _ := strconv.Atoi(sId) id, _ := strconv.Atoi(sId)
@ -164,8 +154,7 @@ func JWTAuthMiddleware() gin.HandlerFunc {
// 验证令牌 // 验证令牌
if err != nil || !token.Valid { if err != nil || !token.Valid {
c.AbortWithStatus(200) c.AbortWithStatusJSON(http.StatusOK, gin.H{
c.JSON(200, gin.H{
"message": "NOT_LOGIN", "message": "NOT_LOGIN",
"error": "Invalid token", "error": "Invalid token",
"code": proto.TokenExpired, "code": proto.TokenExpired,
@ -178,8 +167,7 @@ func JWTAuthMiddleware() gin.HandlerFunc {
c.Set("username", token.Claims.(jwt.MapClaims)["username"]) c.Set("username", token.Claims.(jwt.MapClaims)["username"])
if UserFuncIntercept(int(token.Claims.(jwt.MapClaims)["id"].(float64)), c.Request.URL.Path) { if UserFuncIntercept(int(token.Claims.(jwt.MapClaims)["id"].(float64)), c.Request.URL.Path) {
c.AbortWithStatus(200) c.AbortWithStatusJSON(http.StatusOK, gin.H{
c.JSON(http.StatusOK, gin.H{
"message": "no function permission", "message": "no function permission",
"error": "no permission", "error": "no permission",
"code": proto.NoPermission, "code": proto.NoPermission,