diff options
| author | Bobby <[email protected]> | 2025-07-13 14:22:20 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2025-07-13 14:22:20 +0530 |
| commit | 3d7f8602d45583f25e2428bf6f8123453646dc08 (patch) | |
| tree | ecd707d298099ae9fda55efc3f0d1daf48f7b6e9 /utils/auth | |
| parent | bf112649d039f8f02e2135a74d8b506f7c31c784 (diff) | |
| download | imageboard-3d7f8602d45583f25e2428bf6f8123453646dc08.tar.xz imageboard-3d7f8602d45583f25e2428bf6f8123453646dc08.zip | |
registration controllers and email sending support
Diffstat (limited to 'utils/auth')
| -rw-r--r-- | utils/auth/auth.go | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/utils/auth/auth.go b/utils/auth/auth.go new file mode 100644 index 0000000..7b8f260 --- /dev/null +++ b/utils/auth/auth.go @@ -0,0 +1,26 @@ +package auth + +import ( + "imageboard/models" + + "github.com/gofiber/fiber/v2" +) + +func GetCurrentUser(ctx *fiber.Ctx) *models.User { + if user, ok := ctx.Locals("User").(*models.User); ok { + return user + } + return nil +} + +func IsAuthenticated(ctx *fiber.Ctx) bool { + return GetCurrentUser(ctx) != nil +} + +func GetRedirectURL(ctx *fiber.Ctx) string { + referer := ctx.Get("Referer") + if referer != "" && referer != ctx.BaseURL()+"/login" && referer != ctx.BaseURL()+"/register" { + return referer + } + return "/" +} |
