diff options
| author | Bobby <[email protected]> | 2026-03-07 14:25:54 +0530 |
|---|---|---|
| committer | Bobby <[email protected]> | 2026-03-07 14:25:54 +0530 |
| commit | 41926c10ea2e8496ce4b528262f5047ccbe6f155 (patch) | |
| tree | 67ff5a27bb50faec368cf7ef38a1b1f2866459dd /controllers | |
| parent | ed2a033d7c08e448f5c6fd035e2de8f51431b597 (diff) | |
| download | dove-41926c10ea2e8496ce4b528262f5047ccbe6f155.tar.xz dove-41926c10ea2e8496ce4b528262f5047ccbe6f155.zip | |
Implement authentication system with login/logout functionality and session management
Diffstat (limited to 'controllers')
| -rw-r--r-- | controllers/auth.go | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/controllers/auth.go b/controllers/auth.go new file mode 100644 index 0000000..444026a --- /dev/null +++ b/controllers/auth.go @@ -0,0 +1,33 @@ +package controllers + +import ( + "dove/services" + "dove/types" + "dove/utils/meta" + "dove/utils/shortcuts" + + "github.com/gofiber/fiber/v2" +) + +func Login(context *fiber.Ctx) error { + body, parseError := meta.Body[types.LoginRequest](context) + if parseError != nil { + return shortcuts.BadRequest(context, parseError) + } + + _, serviceError := services.Authenticate(context, body) + if serviceError != nil { + return shortcuts.HandleError(context, serviceError) + } + + return shortcuts.Redirect(context, "dashboard.index") +} + +func Logout(context *fiber.Ctx) error { + _, serviceError := services.Deauthenticate(context) + if serviceError != nil { + return shortcuts.HandleError(context, serviceError) + } + + return shortcuts.Redirect(context, "home") +}
\ No newline at end of file |
