From 3036abbc4af1e85e3f3d473c9facdeefb94916c7 Mon Sep 17 00:00:00 2001 From: Bobby <30593201+luciferreeves@users.noreply.github.com> Date: Tue, 23 Dec 2025 10:57:04 +0530 Subject: email templates, routes and utils --- router/auth.go | 13 +++- router/base.go | 10 ++- router/mail.go | 10 +-- templates/auth/login.django | 36 ++++++----- templates/error.django | 10 +-- templates/layouts/generic.django | 17 +++-- templates/layouts/mailbox.django | 17 +++++ templates/layouts/main.django | 59 +++++++++++++++++ templates/mail/folder.django | 5 ++ templates/partials/filters.django | 129 ++++++++++++++++++++++++++++++++++++++ templates/partials/footer.django | 3 + templates/partials/navbar.django | 124 ++++++++++++++++++++++++++++++++++++ templates/partials/pane.django | 32 ++++++++++ templates/partials/preview.django | 46 ++++++++++++++ templates/partials/sidebar.django | 28 +++++++++ utils/email/helpers.go | 9 +++ 16 files changed, 508 insertions(+), 40 deletions(-) create mode 100644 templates/layouts/mailbox.django create mode 100644 templates/layouts/main.django create mode 100644 templates/mail/folder.django create mode 100644 templates/partials/filters.django create mode 100644 templates/partials/footer.django create mode 100644 templates/partials/navbar.django create mode 100644 templates/partials/pane.django create mode 100644 templates/partials/preview.django create mode 100644 templates/partials/sidebar.django create mode 100644 utils/email/helpers.go diff --git a/router/auth.go b/router/auth.go index 728e985..665b84e 100644 --- a/router/auth.go +++ b/router/auth.go @@ -3,14 +3,23 @@ package router import ( "lain/controllers" "lain/types" + "lain/utils/auth" + "lain/utils/shortcuts" "lain/utils/urls" + + "github.com/gofiber/fiber/v2" ) func init() { urls.SetNamespace("auth") - urls.Path(types.GET, "/login", controllers.LoginPage, "login") - urls.Path(types.GET, "/logout", controllers.Logout, "logout") + urls.Path(types.GET, "/login", func(c *fiber.Ctx) error { + if auth.IsAuthenticated(c) { + return shortcuts.Redirect(c, "mail.inbox") + } + return controllers.LoginPage(c) + }, "login") + urls.Path(types.GET, "/logout", controllers.Logout, "logout") urls.Path(types.POST, "/login", controllers.Login, "login.submit") } diff --git a/router/base.go b/router/base.go index a5e8e96..ece2df6 100644 --- a/router/base.go +++ b/router/base.go @@ -2,12 +2,20 @@ package router import ( "lain/types" + "lain/utils/auth" "lain/utils/shortcuts" "lain/utils/urls" + + "github.com/gofiber/fiber/v2" ) func init() { urls.SetNamespace("") - urls.Path(types.GET, "/", shortcuts.RedirectTo("auth.login"), "home") + urls.Path(types.GET, "/", func(c *fiber.Ctx) error { + if auth.IsAuthenticated(c) { + return shortcuts.Redirect(c, "mail.inbox") + } + return shortcuts.Redirect(c, "auth.login") + }, "home") } diff --git a/router/mail.go b/router/mail.go index 8584f05..9076d97 100644 --- a/router/mail.go +++ b/router/mail.go @@ -1,19 +1,15 @@ package router import ( - "lain/session" + "lain/controllers" "lain/types" "lain/utils/auth" "lain/utils/urls" - - "github.com/gofiber/fiber/v2" ) func init() { urls.SetNamespace("mail") - urls.Path(types.GET, "/inbox", auth.RequireAuthentication(func(c *fiber.Ctx) error { - email, _ := session.GetSessionEmail(c) - return c.SendString("Inbox for " + email) - }), "inbox") + urls.Path(types.GET, "/inbox", auth.RequireAuthentication(controllers.Mailbox), "inbox") + urls.Path(types.GET, "/*", auth.RequireAuthentication(controllers.Mailbox), "folder") } diff --git a/templates/auth/login.django b/templates/auth/login.django index 33ed81a..355c7ba 100644 --- a/templates/auth/login.django +++ b/templates/auth/login.django @@ -1,25 +1,27 @@ {% extends 'layouts/generic.django' %} {% block content %} -
{{ AppDescription }}
+{{ AppDescription }}
- {% if Error %} -{{ ErrorMessage }}
- Go back home +No emails in this folder
+Select an email to view
+