aboutsummaryrefslogtreecommitdiff
path: root/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'controllers')
-rw-r--r--controllers/auth.go33
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