智慧食堂
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
656 B

  1. package mw
  2. import (
  3. "applet/app/admin/md"
  4. "applet/app/admin/svc"
  5. "applet/app/e"
  6. "applet/app/utils"
  7. "fmt"
  8. "github.com/gin-gonic/gin"
  9. )
  10. // CheckPermission 检查权限
  11. func CheckPermission(c *gin.Context) {
  12. admin := svc.GetUser(c)
  13. rolePermissionKey := fmt.Sprintf(md.AdminRolePermissionKey, utils.GetIP(c.Request), utils.AnyToString(admin.AdmId))
  14. isHasPermission, err := svc.CheckUserRole(rolePermissionKey, c.Request.RequestURI, admin.AdmId)
  15. if err != nil {
  16. e.OutErr(c, e.ERR, err.Error())
  17. return
  18. }
  19. if !isHasPermission {
  20. e.OutErr(c, e.ERR_FORBIDEN, "当前用户暂未拥有该路由权限,请联系管理员")
  21. return
  22. }
  23. c.Next()
  24. }