新增权限认证。
This commit is contained in:
+31
-14
@@ -6,6 +6,7 @@ import (
|
||||
"hospital-admin-api/api/responses"
|
||||
"hospital-admin-api/consts"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -64,6 +65,13 @@ func Auth() gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
|
||||
// 检测角色是否已被禁用
|
||||
if adminRole.RoleStatus == 2 {
|
||||
responses.FailWithMessage("角色已被禁用", c)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
|
||||
// 获取角色菜单id
|
||||
AdminRoleMenuDao := dao.AdminRoleMenuDao{}
|
||||
adminRoleMenu, _ := AdminRoleMenuDao.GetAdminRoleMenuListByRoleId(roleId)
|
||||
@@ -95,22 +103,31 @@ func Auth() gin.HandlerFunc {
|
||||
}
|
||||
}
|
||||
|
||||
path := ""
|
||||
// 找到最后一个数字的索引
|
||||
lastSlashIndex := strings.LastIndex(c.Request.RequestURI, "/")
|
||||
if lastSlashIndex != -1 {
|
||||
// 替换最后一个数字部分为 :id
|
||||
path = c.Request.RequestURI[:lastSlashIndex] + "/:id" + c.Request.Method
|
||||
path := c.Request.URL.Path
|
||||
|
||||
// 编译正则表达式
|
||||
reg := regexp.MustCompile("/(\\d+)$")
|
||||
|
||||
// 进行匹配
|
||||
match := reg.MatchString(c.Request.RequestURI)
|
||||
if match {
|
||||
// 找到最后一个数字的索引
|
||||
lastSlashIndex := strings.LastIndex(c.Request.RequestURI, "/")
|
||||
if lastSlashIndex != -1 {
|
||||
// 替换最后一个数字部分为 :id
|
||||
path = path[:lastSlashIndex] + "/:id" + c.Request.Method
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "请求路径错误",
|
||||
"code": consts.SERVER_ERROR,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
} else {
|
||||
c.JSON(http.StatusOK, gin.H{
|
||||
"message": "请求路径错误",
|
||||
"code": consts.SERVER_ERROR,
|
||||
"data": "",
|
||||
})
|
||||
|
||||
c.Abort()
|
||||
return
|
||||
path = path + c.Request.Method
|
||||
}
|
||||
|
||||
// 在apiPermissions中查找对应的API权限
|
||||
|
||||
Reference in New Issue
Block a user