智慧食堂
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.

33 lines
813 B

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