新增退出登陆,新增jwt中int64类型错误问题
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
package middlewares
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/gin-gonic/gin"
|
||||
"hospital-admin-api/api/dao"
|
||||
"hospital-admin-api/api/responses"
|
||||
@@ -29,6 +30,8 @@ func Auth() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(1111)
|
||||
|
||||
// 获取用户数据
|
||||
adminUserDao := dao.AdminUserDao{}
|
||||
adminUser, err := adminUserDao.GetAdminUserFirstById(userId)
|
||||
@@ -65,12 +68,6 @@ func Auth() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// 超级管理员不验证权限
|
||||
if adminRole.IsAdmin == 1 {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
// 检测角色是否已被禁用
|
||||
if adminRole.RoleStatus == 2 {
|
||||
responses.FailWithMessage("角色已被禁用", c)
|
||||
@@ -78,6 +75,12 @@ func Auth() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// 超级管理员不验证权限
|
||||
if adminRole.IsAdmin == 1 {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取用户部门数据
|
||||
if adminUser.DeptID != 0 {
|
||||
adminDeptDao := dao.AdminDeptDao{}
|
||||
|
||||
+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