data clean
This commit is contained in:
@@ -12,19 +12,20 @@ import (
|
||||
)
|
||||
|
||||
// Permission 拦截器
|
||||
func CheckPermission(config *config.Config, rbac rbac.IRbac, jwt *jwt.JWT) gin.HandlerFunc {
|
||||
func CheckPermission(config *config.Config, rbac rbac.IRbac) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
if config.App.Mode != "production" {
|
||||
c.Next()
|
||||
return
|
||||
}
|
||||
|
||||
claim, err := jwt.GetClaims(c)
|
||||
if err != nil {
|
||||
claimsCtx, exists := c.Get(jwt.CtxKey)
|
||||
if !exists {
|
||||
gen.NewBusError(http.StatusBadRequest, http.StatusBadRequest, "Token 获取失败").JSON(c, false)
|
||||
c.Abort()
|
||||
return
|
||||
}
|
||||
claims := claimsCtx.(jwt.Claims)
|
||||
|
||||
//获取请求的PATH
|
||||
path := c.Request.URL.Path
|
||||
@@ -33,7 +34,7 @@ func CheckPermission(config *config.Config, rbac rbac.IRbac, jwt *jwt.JWT) gin.H
|
||||
method := c.Request.Method
|
||||
|
||||
// 获取用户的角色
|
||||
role := strconv.Itoa(int(claim.RoleID))
|
||||
role := strconv.Itoa(int(claims.Role))
|
||||
|
||||
if rbac.Can(role, method, path) == false {
|
||||
gen.NewBusError(http.StatusForbidden, http.StatusForbidden, "未登录或非法访问").JSON(c, false)
|
||||
|
||||
Reference in New Issue
Block a user