From 2552b8ad8f268c5f3d965dfe6db78965d652afa4 Mon Sep 17 00:00:00 2001 From: fabio Date: Mon, 23 Feb 2026 17:09:35 +0100 Subject: [PATCH] genarato alcuni partials e corretto drop down --- README.md | 1 - flowbite-ui/input.css | 12 + internal/controllers/admin_controller.go | 2 + internal/controllers/auth_controller.go | 13 +- internal/controllers/render.go | 4 + internal/controllers/users_controller.go | 2 + internal/http/middleware/auth.go | 2 +- internal/http/router.go | 1 + web/static/css/app.css | 37 ++- web/static/vendor/flags/ch.svg | 5 + web/static/vendor/flags/de.svg | 5 + web/static/vendor/flags/en.svg | 11 + web/static/vendor/flags/en_us.svg | 12 + web/static/vendor/flags/fr.svg | 5 + web/static/vendor/flags/it.svg | 5 + web/templates/admin/_navbar.html | 53 ++++ web/templates/admin/audit_logs.html | 14 +- web/templates/admin/dashboard.html | 16 +- web/templates/admin/users.html | 4 +- web/templates/admin/users/_modal.html | 22 +- web/templates/admin/users/_table.html | 24 +- web/templates/admin/users/index.html | 26 +- web/templates/layout.html | 267 +++++++++++++----- web/templates/partials/language_dropdown.html | 19 ++ web/templates/private/_navbar.html | 52 ++++ web/templates/private/users/index.html | 49 ---- web/templates/private/welcome.html | 14 +- web/templates/public/_navbar.html | 61 ++++ web/templates/public/forbidden.html | 9 + web/templates/public/forgot_password.html | 10 +- web/templates/public/home.html | 7 +- web/templates/public/login.html | 14 +- web/templates/public/reset_password.html | 10 +- web/templates/public/signup.html | 12 +- web/templates/public/verify_notice.html | 8 +- 35 files changed, 587 insertions(+), 221 deletions(-) create mode 100644 web/static/vendor/flags/ch.svg create mode 100644 web/static/vendor/flags/de.svg create mode 100644 web/static/vendor/flags/en.svg create mode 100644 web/static/vendor/flags/en_us.svg create mode 100644 web/static/vendor/flags/fr.svg create mode 100644 web/static/vendor/flags/it.svg create mode 100644 web/templates/admin/_navbar.html create mode 100644 web/templates/partials/language_dropdown.html create mode 100644 web/templates/private/_navbar.html delete mode 100644 web/templates/private/users/index.html create mode 100644 web/templates/public/_navbar.html create mode 100644 web/templates/public/forbidden.html diff --git a/README.md b/README.md index c5e64c9..bcb79b0 100644 --- a/README.md +++ b/README.md @@ -62,7 +62,6 @@ DB_PG_DSN=postgres://trustcontact:trustcontact@localhost:5432/trustcontact?sslmo - Public: `web/templates/public` - Private: `web/templates/private` - Admin: `web/templates/admin` -- Components Flowbite: `web/templates/components` ## Email in Develop diff --git a/flowbite-ui/input.css b/flowbite-ui/input.css index f7c8b18..72b0504 100644 --- a/flowbite-ui/input.css +++ b/flowbite-ui/input.css @@ -3,3 +3,15 @@ @source "../web/static/**/*.js"; @source "./node_modules/flowbite/**/*.js"; @import "tailwindcss"; + +@layer utilities { + .flag-lang { + width: 32px; + height: 22px; + } + + .flag-lang-ch { + width: 22px; + height: 22px; + } +} diff --git a/internal/controllers/admin_controller.go b/internal/controllers/admin_controller.go index ed77f1b..a97d119 100644 --- a/internal/controllers/admin_controller.go +++ b/internal/controllers/admin_controller.go @@ -23,6 +23,8 @@ func (ac *AdminController) Dashboard(c *fiber.Ctx) error { tmpl, err := template.ParseFiles( "web/templates/layout.html", + "web/templates/admin/_navbar.html", + "web/templates/partials/language_dropdown.html", "web/templates/public/_flash.html", "web/templates/admin/dashboard.html", ) diff --git a/internal/controllers/auth_controller.go b/internal/controllers/auth_controller.go index 3202368..9d9b956 100644 --- a/internal/controllers/auth_controller.go +++ b/internal/controllers/auth_controller.go @@ -19,13 +19,9 @@ func NewAuthController(authService *services.AuthService) *AuthController { } func (ac *AuthController) ShowHome(c *fiber.Ctx) error { - if _, ok := httpmw.CurrentUserFromContext(c); ok { - return c.Redirect("/welcome") - } - return renderPublic(c, "home.html", map[string]any{ "Title": "Home", - "NavSection": "public", + "NavSection": "home", }) } @@ -145,6 +141,13 @@ func (ac *AuthController) ShowVerifyNotice(c *fiber.Ctx) error { }) } +func (ac *AuthController) ShowForbidden(c *fiber.Ctx) error { + return renderPublic(c, "forbidden.html", map[string]any{ + "Title": "Forbidden", + "NavSection": "public", + }) +} + func (ac *AuthController) ShowForgotPassword(c *fiber.Ctx) error { return renderPublic(c, "forgot_password.html", map[string]any{ "Title": "Forgot password", diff --git a/internal/controllers/render.go b/internal/controllers/render.go index 1997a00..c30abb2 100644 --- a/internal/controllers/render.go +++ b/internal/controllers/render.go @@ -26,6 +26,8 @@ func renderPublic(c *fiber.Ctx, page string, data map[string]any) error { files := []string{ "web/templates/layout.html", + "web/templates/public/_navbar.html", + "web/templates/partials/language_dropdown.html", "web/templates/public/_flash.html", filepath.Join("web/templates/public", page), } @@ -62,6 +64,8 @@ func renderPrivate(c *fiber.Ctx, page string, data map[string]any) error { files := []string{ "web/templates/layout.html", + "web/templates/private/_navbar.html", + "web/templates/partials/language_dropdown.html", "web/templates/public/_flash.html", filepath.Join("web/templates/private", page), } diff --git a/internal/controllers/users_controller.go b/internal/controllers/users_controller.go index 6ab15a3..1f3dcee 100644 --- a/internal/controllers/users_controller.go +++ b/internal/controllers/users_controller.go @@ -38,6 +38,8 @@ func (uc *UsersController) Index(c *fiber.Ctx) error { tmpl, err := template.ParseFiles( "web/templates/layout.html", + "web/templates/admin/_navbar.html", + "web/templates/partials/language_dropdown.html", "web/templates/public/_flash.html", "web/templates/admin/users/index.html", "web/templates/admin/users/_table.html", diff --git a/internal/http/middleware/auth.go b/internal/http/middleware/auth.go index d2662b8..e928bbe 100644 --- a/internal/http/middleware/auth.go +++ b/internal/http/middleware/auth.go @@ -25,7 +25,7 @@ func RequireAdmin() fiber.Handler { return c.Redirect("/login") } if user.Role != models.RoleAdmin { - return c.Status(fiber.StatusForbidden).SendString("forbidden") + return c.Status(fiber.StatusForbidden).Redirect("/forbidden") } return c.Next() } diff --git a/internal/http/router.go b/internal/http/router.go index 8974f98..ee4417f 100644 --- a/internal/http/router.go +++ b/internal/http/router.go @@ -48,6 +48,7 @@ func RegisterRoutes(app *fiber.App, store *session.Store, database *gorm.DB, cfg app.Post("/forgot-password", authController.ForgotPassword) app.Get("/reset-password", authController.ShowResetPassword) app.Post("/reset-password", authController.ResetPassword) + app.Get("/forbidden", authController.ShowForbidden) app.Get("/welcome", httpmw.RequireAuth(), authController.ShowWelcome) private := app.Group("/private", httpmw.RequireAuth(), httpmw.RequireAdmin()) diff --git a/web/static/css/app.css b/web/static/css/app.css index e74da59..19a52f8 100644 --- a/web/static/css/app.css +++ b/web/static/css/app.css @@ -901,6 +901,9 @@ .mx-auto { margin-inline: auto; } + .my-2 { + margin-block: calc(var(--spacing) * 2); + } .my-4 { margin-block: calc(var(--spacing) * 4); } @@ -1460,6 +1463,9 @@ .w-10 { width: calc(var(--spacing) * 10); } + .w-40 { + width: calc(var(--spacing) * 40); + } .w-44 { width: calc(var(--spacing) * 44); } @@ -1549,6 +1555,9 @@ border-color: var(--color-blue-600); } } + .min-w-\[95px\] { + min-width: 95px; + } .flex-1 { flex: 1; } @@ -1734,6 +1743,9 @@ .overflow-y-auto { overflow-y: auto; } + .rounded { + border-radius: 0.25rem; + } .rounded-full { border-radius: calc(infinity * 1px); } @@ -2083,6 +2095,9 @@ stroke: var(--color-gray-700) !important; } } + .object-cover { + object-fit: cover; + } .apexcharts-legend { .apexcharts-canvas & { padding: 0 !important; @@ -2138,6 +2153,9 @@ .py-0\.5 { padding-block: calc(var(--spacing) * 0.5); } + .py-1 { + padding-block: calc(var(--spacing) * 1); + } .py-2 { padding-block: calc(var(--spacing) * 2); } @@ -2274,6 +2292,10 @@ --tw-leading: calc(var(--spacing) * 9); line-height: calc(var(--spacing) * 9); } + .leading-none { + --tw-leading: 1; + line-height: 1; + } .leading-relaxed { --tw-leading: var(--leading-relaxed); line-height: var(--leading-relaxed); @@ -2600,11 +2622,6 @@ margin-inline-start: calc(var(--spacing) * 4); } } - .md\:me-0 { - @media (width >= 48rem) { - margin-inline-end: calc(var(--spacing) * 0); - } - } .md\:mt-0 { @media (width >= 48rem) { margin-top: calc(var(--spacing) * 0); @@ -2900,6 +2917,16 @@ } } } +@layer utilities { + .flag-lang { + width: 32px; + height: 22px; + } + .flag-lang-ch { + width: 22px; + height: 22px; + } +} @layer base { .tooltip-arrow,.tooltip-arrow:before { position: absolute; diff --git a/web/static/vendor/flags/ch.svg b/web/static/vendor/flags/ch.svg new file mode 100644 index 0000000..df92656 --- /dev/null +++ b/web/static/vendor/flags/ch.svg @@ -0,0 +1,5 @@ + diff --git a/web/static/vendor/flags/de.svg b/web/static/vendor/flags/de.svg new file mode 100644 index 0000000..cacb423 --- /dev/null +++ b/web/static/vendor/flags/de.svg @@ -0,0 +1,5 @@ + diff --git a/web/static/vendor/flags/en.svg b/web/static/vendor/flags/en.svg new file mode 100644 index 0000000..b321789 --- /dev/null +++ b/web/static/vendor/flags/en.svg @@ -0,0 +1,11 @@ + diff --git a/web/static/vendor/flags/en_us.svg b/web/static/vendor/flags/en_us.svg new file mode 100644 index 0000000..881f770 --- /dev/null +++ b/web/static/vendor/flags/en_us.svg @@ -0,0 +1,12 @@ + diff --git a/web/static/vendor/flags/fr.svg b/web/static/vendor/flags/fr.svg new file mode 100644 index 0000000..574a3e8 --- /dev/null +++ b/web/static/vendor/flags/fr.svg @@ -0,0 +1,5 @@ + diff --git a/web/static/vendor/flags/it.svg b/web/static/vendor/flags/it.svg new file mode 100644 index 0000000..83c5b96 --- /dev/null +++ b/web/static/vendor/flags/it.svg @@ -0,0 +1,5 @@ + diff --git a/web/templates/admin/_navbar.html b/web/templates/admin/_navbar.html new file mode 100644 index 0000000..c9b5566 --- /dev/null +++ b/web/templates/admin/_navbar.html @@ -0,0 +1,53 @@ +{{define "navbar"}} + +{{end}} + +{{define "navbar_controls"}} +{{template "language_dropdown" .}} + +{{if .CurrentUser}} +
+ + +
+{{end}} +{{end}} diff --git a/web/templates/admin/audit_logs.html b/web/templates/admin/audit_logs.html index 9859ab4..8ed736c 100644 --- a/web/templates/admin/audit_logs.html +++ b/web/templates/admin/audit_logs.html @@ -1,14 +1,14 @@ {{define "content"}}
-

Audit Logs

+

Audit Logs

@@ -18,14 +18,18 @@
- + + + + +
TimestampActorAction
TimestampActorAction
---
diff --git a/web/templates/admin/dashboard.html b/web/templates/admin/dashboard.html index 7e2417b..484d98f 100644 --- a/web/templates/admin/dashboard.html +++ b/web/templates/admin/dashboard.html @@ -1,28 +1,28 @@ {{define "content"}}
-

Admin Dashboard

-

Area amministrazione.

+

Admin Dashboard

+

Area amministrazione.

-

Utenti

+

Utenti

{{if .PageData}}{{.PageData.Total}}{{else}}-{{end}}

-

Ruolo corrente

+

Ruolo corrente

{{if and .CurrentUser (eq .CurrentUser.Role "admin")}} - admin + admin {{else}} - user + user {{end}}

diff --git a/web/templates/admin/users.html b/web/templates/admin/users.html index af2c29b..c8a9f49 100644 --- a/web/templates/admin/users.html +++ b/web/templates/admin/users.html @@ -1,8 +1,8 @@ {{define "content"}}
-

Admin Users

+

Admin Users

-

Template pagina utenti admin in stile Flowbite.

+

Template pagina utenti admin in stile Flowbite.

{{end}} diff --git a/web/templates/admin/users/_modal.html b/web/templates/admin/users/_modal.html index 046a4c3..1ffa528 100644 --- a/web/templates/admin/users/_modal.html +++ b/web/templates/admin/users/_modal.html @@ -1,36 +1,36 @@ {{define "users_modal"}}
- ID: + ID: {{.User.ID}}
- Role: + Role: {{if eq .User.Role "admin"}} - admin + admin {{else}} - user + user {{end}}
- Name: + Name: {{if .User.Name}}{{.User.Name}}{{else}}-{{end}}
- Email: + Email: {{.User.Email}}
- Verified: - {{if .User.EmailVerified}}yes{{else}}no{{end}} + Verified: + {{if .User.EmailVerified}}yes{{else}}no{{end}}
- Created: - {{.User.CreatedAt}} + Created: + {{.User.CreatedAt}}
- +
{{end}} diff --git a/web/templates/admin/users/_table.html b/web/templates/admin/users/_table.html index 1e18f02..8c23c7a 100644 --- a/web/templates/admin/users/_table.html +++ b/web/templates/admin/users/_table.html @@ -5,16 +5,16 @@ - + - + - + - Role - Azioni + Role + Azioni @@ -25,18 +25,18 @@ {{$u.Email}} {{if eq $u.Role "admin"}} - admin + admin {{else}} - user + user {{end}} - + {{else}} - Nessun utente trovato. + Nessun utente trovato. {{end}} @@ -44,10 +44,10 @@
-
Totale: {{$p.Total}} utenti. Pagina {{$p.Page}}{{if gt $p.TotalPages 0}} / {{$p.TotalPages}}{{end}}
+
Totale: {{$p.Total}} utenti. Pagina {{$p.Page}}{{if gt $p.TotalPages 0}} / {{$p.TotalPages}}{{end}}
- - + +
{{end}} diff --git a/web/templates/admin/users/index.html b/web/templates/admin/users/index.html index 74236bc..6d5c1d9 100644 --- a/web/templates/admin/users/index.html +++ b/web/templates/admin/users/index.html @@ -2,25 +2,25 @@
-

Users

-

Ricerca, ordinamento e paging server-side via HTMX.

+

Users

+

Ricerca, ordinamento e paging server-side via HTMX.

-
- - + +
- +
- +
@@ -36,9 +36,9 @@
-

Dettaglio utente

+

Dettaglio utente

-

Placeholder UI Flowbite. La creazione utente può essere collegata a una route backend quando disponibile.

+

Placeholder UI Flowbite. La creazione utente può essere collegata a una route backend quando disponibile.

- +
diff --git a/web/templates/layout.html b/web/templates/layout.html index e31159c..d83cbf1 100644 --- a/web/templates/layout.html +++ b/web/templates/layout.html @@ -8,82 +8,209 @@ - - - -
+
{{template "_flash.html" .}} {{template "content" .}}
-
- Trustcontact -
+
Trustcontact
+ + diff --git a/web/templates/partials/language_dropdown.html b/web/templates/partials/language_dropdown.html new file mode 100644 index 0000000..f306922 --- /dev/null +++ b/web/templates/partials/language_dropdown.html @@ -0,0 +1,19 @@ +{{define "language_dropdown"}} +
+ Italiano + + +
+{{end}} diff --git a/web/templates/private/_navbar.html b/web/templates/private/_navbar.html new file mode 100644 index 0000000..d89c92a --- /dev/null +++ b/web/templates/private/_navbar.html @@ -0,0 +1,52 @@ +{{define "navbar"}} + +{{end}} + +{{define "navbar_controls"}} +{{template "language_dropdown" .}} + +{{if .CurrentUser}} +
+ + +
+{{end}} +{{end}} diff --git a/web/templates/private/users/index.html b/web/templates/private/users/index.html deleted file mode 100644 index 0a011a3..0000000 --- a/web/templates/private/users/index.html +++ /dev/null @@ -1,49 +0,0 @@ -{{define "content"}} -
-
-

Users

- -
- -
- - -
- -
- - - - - - - - - - - - - - - -
NameEmailRole
--user
-
-
- - -{{end}} diff --git a/web/templates/private/welcome.html b/web/templates/private/welcome.html index 0c7f407..39c6e84 100644 --- a/web/templates/private/welcome.html +++ b/web/templates/private/welcome.html @@ -1,19 +1,21 @@ {{define "content"}}
-

Dashboard

+

welcome

{{if .CurrentUser}} -

Bentornato {{if .CurrentUser.Name}}{{.CurrentUser.Name}}{{else}}{{.CurrentUser.Email}}{{end}}.

+

Bentornato {{if .CurrentUser.Name}}{{.CurrentUser.Name}}{{else}}{{.CurrentUser.Email}}{{end}}.

{{else}} -

Benvenuto.

+

Benvenuto.

{{end}}
-

Quick Links

+

Quick Links

- Dashboard - Users + welcome + {{if and .CurrentUser (eq .CurrentUser.Role "admin")}} + Users + {{end}}
diff --git a/web/templates/public/_navbar.html b/web/templates/public/_navbar.html new file mode 100644 index 0000000..6f345f0 --- /dev/null +++ b/web/templates/public/_navbar.html @@ -0,0 +1,61 @@ +{{define "navbar"}} + +{{end}} + +{{define "navbar_controls"}} +{{template "language_dropdown" .}} + +{{if .CurrentUser}} +
+ + +
+{{end}} +{{end}} diff --git a/web/templates/public/forbidden.html b/web/templates/public/forbidden.html new file mode 100644 index 0000000..d48f09e --- /dev/null +++ b/web/templates/public/forbidden.html @@ -0,0 +1,9 @@ +{{define "content"}} +
+
+

Accesso negato

+

Non hai i privilegi necessari per accedere a questa pagina.

+ Torna alla home +
+
+{{end}} diff --git a/web/templates/public/forgot_password.html b/web/templates/public/forgot_password.html index aaf0042..8cc2238 100644 --- a/web/templates/public/forgot_password.html +++ b/web/templates/public/forgot_password.html @@ -1,18 +1,18 @@ {{define "content"}}
-

Forgot Password

-

Inserisci la tua email per ricevere il link di reset.

+

Forgot Password

+

Inserisci la tua email per ricevere il link di reset.

- +
- + -

Torna al login

+

Torna al login

diff --git a/web/templates/public/home.html b/web/templates/public/home.html index 19f8096..9530510 100644 --- a/web/templates/public/home.html +++ b/web/templates/public/home.html @@ -1,10 +1,5 @@ {{define "content"}}
-

Trustcontact

-

Accedi o registrati per continuare.

- +

Home Page

{{end}} diff --git a/web/templates/public/login.html b/web/templates/public/login.html index 93cd15e..c92b67b 100644 --- a/web/templates/public/login.html +++ b/web/templates/public/login.html @@ -1,25 +1,25 @@ {{define "content"}}
-

Login

-

Accedi al tuo account.

+

Login

+

Accedi al tuo account.

- +
- +
- +
diff --git a/web/templates/public/reset_password.html b/web/templates/public/reset_password.html index cff9a66..1cd7ae3 100644 --- a/web/templates/public/reset_password.html +++ b/web/templates/public/reset_password.html @@ -1,20 +1,20 @@ {{define "content"}}
-

Reset Password

-

Imposta una nuova password.

+

Reset Password

+

Imposta una nuova password.

{{if .Token}}
- +
- +
{{else}} - + {{end}}
diff --git a/web/templates/public/signup.html b/web/templates/public/signup.html index 2b1b602..b84b763 100644 --- a/web/templates/public/signup.html +++ b/web/templates/public/signup.html @@ -1,23 +1,23 @@ {{define "content"}}
-

Signup

-

Crea il tuo account.

+

Signup

+

Crea il tuo account.

- +
- +
- + -

Hai già un account? Accedi

+

Hai già un account? Accedi

diff --git a/web/templates/public/verify_notice.html b/web/templates/public/verify_notice.html index 8176aa6..80707b3 100644 --- a/web/templates/public/verify_notice.html +++ b/web/templates/public/verify_notice.html @@ -1,8 +1,8 @@ {{define "content"}}
-

Verifica email

-

Controlla la casella di posta e apri il link di verifica ricevuto.

-

Se il link è scaduto, ripeti la registrazione o contatta supporto.

- Vai al login +

Verifica email

+

Controlla la casella di posta e apri il link di verifica ricevuto.

+

Se il link è scaduto, ripeti la registrazione o contatta supporto.

+ Vai al login
{{end}}