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 /router | |
| parent | ed2a033d7c08e448f5c6fd035e2de8f51431b597 (diff) | |
| download | dove-41926c10ea2e8496ce4b528262f5047ccbe6f155.tar.xz dove-41926c10ea2e8496ce4b528262f5047ccbe6f155.zip | |
Implement authentication system with login/logout functionality and session management
Diffstat (limited to 'router')
| -rw-r--r-- | router/auth.go | 14 | ||||
| -rw-r--r-- | router/base.go | 13 | ||||
| -rw-r--r-- | router/dashboard.go | 14 | ||||
| -rw-r--r-- | router/router.go | 33 |
4 files changed, 74 insertions, 0 deletions
diff --git a/router/auth.go b/router/auth.go new file mode 100644 index 0000000..f8f41fc --- /dev/null +++ b/router/auth.go @@ -0,0 +1,14 @@ +package router + +import ( + "dove/controllers" + "dove/enums" + "dove/utils/urls" +) + +func init() { + urls.SetNamespace("auth") + + urls.Path(enums.Post, "/login", controllers.Login, "login") + urls.Path(enums.Get, "/logout", controllers.Logout, "logout") +} diff --git a/router/base.go b/router/base.go new file mode 100644 index 0000000..3a5e7ee --- /dev/null +++ b/router/base.go @@ -0,0 +1,13 @@ +package router + +import ( + "dove/enums" + "dove/pages" + "dove/utils/urls" +) + +func init() { + urls.SetNamespace("") + + urls.Path(enums.Get, "/", pages.Home, "home") +} diff --git a/router/dashboard.go b/router/dashboard.go new file mode 100644 index 0000000..1ab4dda --- /dev/null +++ b/router/dashboard.go @@ -0,0 +1,14 @@ +package router + +import ( + "dove/enums" + "dove/pages" + "dove/utils/auth" + "dove/utils/urls" +) + +func init() { + urls.SetNamespace("dashboard") + + urls.Path(enums.Get, "/", auth.RequireAuthentication(pages.Dashboard), "index") +} diff --git a/router/router.go b/router/router.go new file mode 100644 index 0000000..68ecad9 --- /dev/null +++ b/router/router.go @@ -0,0 +1,33 @@ +package router + +import ( + "dove/utils/shortcuts" + "dove/utils/urls" + + "github.com/gofiber/fiber/v2" +) + +func Initialize(application *fiber.App) { + application.Static("/static", "./static") + urls.Attach(application) +} + +func ErrorHandler(context *fiber.Ctx, err error) error { + statusCode := fiber.StatusInternalServerError + if fiberError, ok := err.(*fiber.Error); ok { + statusCode = fiberError.Code + } + + switch statusCode { + case fiber.StatusBadRequest: + return shortcuts.BadRequest(context, err) + case fiber.StatusForbidden: + return shortcuts.Forbidden(context, err) + case fiber.StatusNotFound: + return shortcuts.NotFound(context, err) + case fiber.StatusUnauthorized: + return shortcuts.Unauthorized(context, err) + default: + return shortcuts.InternalServerError(context, err) + } +}
\ No newline at end of file |
