| | |
| | | package middleware |
| | | |
| | | import ( |
| | | "aps_crm/constvar" |
| | | "aps_crm/pkg/contextx" |
| | | "aps_crm/pkg/ecode" |
| | | "aps_crm/service" |
| | |
| | | |
| | | // CasbinHandler 拦截器 |
| | | func CasbinHandler() gin.HandlerFunc { |
| | | //return func(c *gin.Context) { |
| | | // waitUse, _ := utils.GetClaims(c) |
| | | // ctx := new(contextx.Context).SetCtx(c) |
| | | // //获取请求的PATH |
| | | // path := c.Request.URL.Path |
| | | // //obj := strings.TrimPrefix(path, global.GVA_CONFIG.System.RouterPrefix) |
| | | // obj := strings.TrimPrefix(path, "") |
| | | // // 获取请求方法 |
| | | // act := c.Request.Method |
| | | // // 获取用户的角色 |
| | | // sub := strconv.Itoa(int(waitUse.AuthorityId)) |
| | | // e := casbinService.Casbin() // 判断策略中是否存在 |
| | | // success, _ := e.Enforce(sub, obj, act) |
| | | // if !success { |
| | | // // response.FailWithDetailed(gin.H{}, "权限不足", c) |
| | | // c.Abort() |
| | | // ctx.Fail(ecode.NoPowerErr) |
| | | // return |
| | | // } |
| | | // c.Next() |
| | | //} |
| | | |
| | | return func(c *gin.Context) { |
| | | waitUse, _ := utils.GetClaims(c) |
| | | ctx := new(contextx.Context).SetCtx(c) |
| | |
| | | act := c.Request.Method |
| | | // 获取用户的角色 |
| | | sub := strconv.Itoa(int(waitUse.AuthorityId)) |
| | | |
| | | // 超级管理员不需要验证权限 |
| | | if waitUse.UserType == constvar.UserTypeSuper { |
| | | c.Next() |
| | | } |
| | | |
| | | e := casbinService.Casbin() // 判断策略中是否存在 |
| | | success, _ := e.Enforce(sub, obj, act) |
| | | if !success { |