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 %} -
-

{{ AppName }}

-

{{ AppDescription }}

+
+
{% endblock %} diff --git a/templates/error.django b/templates/error.django index f766688..d38b972 100644 --- a/templates/error.django +++ b/templates/error.django @@ -1,8 +1,10 @@ {% extends 'layouts/generic.django' %} {% block content %} -
-

{{ ErrorTitle }}

-

{{ ErrorMessage }}

- Go back home +
+
+

{{ ErrorTitle }}

+

{{ ErrorMessage }}

+ Go back home +
{% endblock %} diff --git a/templates/layouts/generic.django b/templates/layouts/generic.django index 3ca183b..3222516 100644 --- a/templates/layouts/generic.django +++ b/templates/layouts/generic.django @@ -2,24 +2,23 @@ - {{ Title }} - {{ Appname }} + {{ Title }} - {% block head %} {% endblock %} -
- {% block content %} + {% block body %} +
+ {% block content %} - {% endblock %} -
+ {% endblock %} +
+ {% endblock %} -
- {{ AppName }} - Powered by {{ AppEngine }} - © shi.foo 2025 -
+ {% include 'partials/footer.django' %} {% block scripts %} diff --git a/templates/layouts/mailbox.django b/templates/layouts/mailbox.django new file mode 100644 index 0000000..ebb0352 --- /dev/null +++ b/templates/layouts/mailbox.django @@ -0,0 +1,17 @@ +{% extends 'layouts/main.django' %} + +{% block content %} +
+ + +
+ {% include 'partials/pane.django' %} +
+ +
+ {% include 'partials/preview.django' %} +
+
+{% endblock %} diff --git a/templates/layouts/main.django b/templates/layouts/main.django new file mode 100644 index 0000000..929f656 --- /dev/null +++ b/templates/layouts/main.django @@ -0,0 +1,59 @@ +{% extends 'layouts/generic.django' %} + +{% block body %} + {% include 'partials/navbar.django' %} +
+ {% block content %} + + {% endblock %} +
+{% endblock %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/mail/folder.django b/templates/mail/folder.django new file mode 100644 index 0000000..4cdce72 --- /dev/null +++ b/templates/mail/folder.django @@ -0,0 +1,5 @@ +{% extends 'layouts/mailbox.django' %} + +{% block scripts %} + +{% endblock %} diff --git a/templates/partials/filters.django b/templates/partials/filters.django new file mode 100644 index 0000000..98765be --- /dev/null +++ b/templates/partials/filters.django @@ -0,0 +1,129 @@ + + + diff --git a/templates/partials/footer.django b/templates/partials/footer.django new file mode 100644 index 0000000..3900a0c --- /dev/null +++ b/templates/partials/footer.django @@ -0,0 +1,3 @@ +
+ {{ AppName }} - Powered by {{ AppEngine }} - © shi.foo 2025 +
diff --git a/templates/partials/navbar.django b/templates/partials/navbar.django new file mode 100644 index 0000000..7b18bc9 --- /dev/null +++ b/templates/partials/navbar.django @@ -0,0 +1,124 @@ + diff --git a/templates/partials/pane.django b/templates/partials/pane.django new file mode 100644 index 0000000..873e9de --- /dev/null +++ b/templates/partials/pane.django @@ -0,0 +1,32 @@ +
+ {% if Emails %} + {% for email in Emails %} + + {% endfor %} + {% else %} +
+

No emails in this folder

+
+ {% endif %} +
diff --git a/templates/partials/preview.django b/templates/partials/preview.django new file mode 100644 index 0000000..dd40109 --- /dev/null +++ b/templates/partials/preview.django @@ -0,0 +1,46 @@ +{% if Email %} + + + + + + + {% if Email.Attachments %} + + {% endif %} + + +{% else %} +
+

Select an email to view

+
+{% endif %} diff --git a/templates/partials/sidebar.django b/templates/partials/sidebar.django new file mode 100644 index 0000000..ea0a72d --- /dev/null +++ b/templates/partials/sidebar.django @@ -0,0 +1,28 @@ + diff --git a/utils/email/helpers.go b/utils/email/helpers.go new file mode 100644 index 0000000..eb95726 --- /dev/null +++ b/utils/email/helpers.go @@ -0,0 +1,9 @@ +package email + +import ( + "slices" +) + +func hasAttribute(attrs []string, attr string) bool { + return slices.Contains(attrs, attr) +} -- cgit v1.2.3