新增退出登陆,新增jwt中int64类型错误问题
This commit is contained in:
+56
-4
@@ -1,11 +1,13 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/consts"
|
||||
"hospital-admin-api/global"
|
||||
"hospital-admin-api/utils"
|
||||
"net/http"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -29,6 +31,7 @@ func Jwt() gin.HandlerFunc {
|
||||
// 检测是否存在黑名单
|
||||
res, _ := global.Redis.Get(c, "jwt_black_"+authorization).Result()
|
||||
|
||||
fmt.Println(res)
|
||||
if res != "" {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误/过期",
|
||||
@@ -53,10 +56,59 @@ func Jwt() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("UserId", t.UserId) // 用户id
|
||||
c.Set("RoleId", t.RoleId) // 角色id
|
||||
c.Set("DeptId", t.DeptId) // 部门id
|
||||
c.Set("PostId", t.PostId) // 岗位id
|
||||
// 转换类型
|
||||
userId, err := strconv.ParseInt(t.UserId, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误",
|
||||
"code": consts.TOKEN_ERROR,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
roleId, err := strconv.ParseInt(t.RoleId, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误",
|
||||
"code": consts.TOKEN_ERROR,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
deptId, err := strconv.ParseInt(t.DeptId, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误",
|
||||
"code": consts.TOKEN_ERROR,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
postId, err := strconv.ParseInt(t.PostId, 10, 64)
|
||||
if err != nil {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "token错误",
|
||||
"code": consts.TOKEN_ERROR,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
c.Set("UserId", userId) // 用户id
|
||||
c.Set("RoleId", roleId) // 角色id
|
||||
c.Set("DeptId", deptId) // 部门id
|
||||
c.Set("PostId", postId) // 岗位id
|
||||
c.Next()
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user