✨ Add some directly callable functions into adaptor
This commit is contained in:
parent
aa624ee454
commit
6bb8eab3fc
@ -1,6 +1,7 @@
|
|||||||
package sec
|
package sec
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"github.com/gofiber/fiber/v2"
|
"github.com/gofiber/fiber/v2"
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
@ -37,3 +38,22 @@ func ValidatorMiddleware(c *fiber.Ctx) error {
|
|||||||
|
|
||||||
return c.Next()
|
return c.Next()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func EnsureAuthenticated(c *fiber.Ctx) error {
|
||||||
|
if _, ok := c.Locals("nex_user").(*UserInfo); !ok {
|
||||||
|
return fiber.NewError(fiber.StatusUnauthorized)
|
||||||
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func EnsureGrantedPerm(c *fiber.Ctx, key string, val any) error {
|
||||||
|
if err := EnsureAuthenticated(c); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
info := c.Locals("nex_user").(*UserInfo)
|
||||||
|
if !info.HasPermNode(key, val) {
|
||||||
|
return fiber.NewError(fiber.StatusForbidden, fmt.Sprintf("missing permission: %s", key))
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user