From 41926c10ea2e8496ce4b528262f5047ccbe6f155 Mon Sep 17 00:00:00 2001 From: Bobby Date: Sat, 7 Mar 2026 14:25:54 +0530 Subject: Implement authentication system with login/logout functionality and session management --- controllers/auth.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 controllers/auth.go (limited to 'controllers') 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 -- cgit v1.2.3