genarato alcuni partials e corretto drop down
This commit is contained in:
@@ -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",
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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),
|
||||
}
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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())
|
||||
|
||||
Reference in New Issue
Block a user