permissions.go 917 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package permission
  2. import (
  3. "github.com/gin-gonic/gin"
  4. )
  5. func CasbinMiddleware() gin.HandlerFunc {
  6. return func(c *gin.Context) {
  7. /*Authorization := c.GetHeader("Authorization")
  8. token := strings.Split(Authorization, " ")
  9. t, _ := jwt.Parse(token[1], func(*jwt.Token) (interface{}, error) {
  10. return jwtGet.JwtSecret, nil
  11. })
  12. fmt.Println(jwtGet.GetIdFromClaims("username", t.Claims), c.Request.URL.Path, c.Request.Method)
  13. if b, err := inject.Obj.Enforcer.EnforceSafe(jwtGet.GetIdFromClaims("username", t.Claims), c.Request.URL.Path, c.Request.Method); err != nil {
  14. c.JSON(http.StatusUnauthorized, gin.H{
  15. "code": http.StatusOK,
  16. "data": err,
  17. "msg": "ok",
  18. })
  19. c.Abort()
  20. return
  21. } else if !b {
  22. c.JSON(http.StatusUnauthorized, gin.H{
  23. "code": http.StatusForbidden,
  24. "data": "登录用户 没有权限",
  25. "msg": "ok",
  26. })
  27. c.Abort()
  28. return
  29. }
  30. c.Next()*/
  31. }
  32. }