remove unused UserDropdown method from AuthController and update routes
This commit is contained in:
parent
82478b98e8
commit
803c83d890
|
|
@ -1,9 +1,7 @@
|
||||||
package controllers
|
package controllers
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
|
||||||
"errors"
|
"errors"
|
||||||
"html/template"
|
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
httpmw "trustcontact/internal/http/middleware"
|
httpmw "trustcontact/internal/http/middleware"
|
||||||
|
|
@ -263,29 +261,3 @@ func (ac *AuthController) UpdateTheme(c *fiber.Ctx) error {
|
||||||
|
|
||||||
return c.SendStatus(fiber.StatusNoContent)
|
return c.SendStatus(fiber.StatusNoContent)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (ac *AuthController) UserDropdown(c *fiber.Ctx) error {
|
|
||||||
currentUser, ok := httpmw.CurrentUserFromContext(c)
|
|
||||||
if !ok {
|
|
||||||
return c.SendStatus(fiber.StatusUnauthorized)
|
|
||||||
}
|
|
||||||
|
|
||||||
files := []string{
|
|
||||||
"web/templates/partials/user_dropdown.html",
|
|
||||||
}
|
|
||||||
tmpl, err := template.ParseFiles(files...)
|
|
||||||
if err != nil {
|
|
||||||
return c.Status(fiber.StatusInternalServerError).SendString("cannot render dropdown")
|
|
||||||
}
|
|
||||||
|
|
||||||
viewData := map[string]any{
|
|
||||||
"CurrentUser": currentUser,
|
|
||||||
}
|
|
||||||
var out bytes.Buffer
|
|
||||||
if err := tmpl.ExecuteTemplate(&out, "user_dropdown", viewData); err != nil {
|
|
||||||
return c.Status(fiber.StatusInternalServerError).SendString("cannot render dropdown")
|
|
||||||
}
|
|
||||||
|
|
||||||
c.Type("html", "utf-8")
|
|
||||||
return c.Send(out.Bytes())
|
|
||||||
}
|
|
||||||
|
|
|
||||||
|
|
@ -30,6 +30,7 @@ func RegisterRoutes(app *fiber.App, store *session.Store, database *gorm.DB, cfg
|
||||||
return fmt.Errorf("init auth service: %w", err)
|
return fmt.Errorf("init auth service: %w", err)
|
||||||
}
|
}
|
||||||
authController := controllers.NewAuthController(authService)
|
authController := controllers.NewAuthController(authService)
|
||||||
|
|
||||||
privateSPADir := filepath.FromSlash("quasar/private_section/dist/spa")
|
privateSPADir := filepath.FromSlash("quasar/private_section/dist/spa")
|
||||||
privateController := controllers.NewPrivateController(privateSPADir)
|
privateController := controllers.NewPrivateController(privateSPADir)
|
||||||
adminSPADir := filepath.FromSlash("quasar/admin_section/dist/spa")
|
adminSPADir := filepath.FromSlash("quasar/admin_section/dist/spa")
|
||||||
|
|
@ -54,7 +55,6 @@ func RegisterRoutes(app *fiber.App, store *session.Store, database *gorm.DB, cfg
|
||||||
app.Get("/forbidden", authController.ShowForbidden)
|
app.Get("/forbidden", authController.ShowForbidden)
|
||||||
app.Post("/preferences/lang", httpmw.RequireAuth(), authController.UpdateLanguage)
|
app.Post("/preferences/lang", httpmw.RequireAuth(), authController.UpdateLanguage)
|
||||||
app.Post("/preferences/theme", httpmw.RequireAuth(), authController.UpdateTheme)
|
app.Post("/preferences/theme", httpmw.RequireAuth(), authController.UpdateTheme)
|
||||||
app.Get("/partials/user-dropdown", httpmw.RequireAuth(), authController.UserDropdown)
|
|
||||||
|
|
||||||
// Quasar admin SPA assets are emitted with absolute paths (/assets, /icons, /favicon.ico).
|
// Quasar admin SPA assets are emitted with absolute paths (/assets, /icons, /favicon.ico).
|
||||||
// Protect them with the same auth/admin middleware used by /admin.
|
// Protect them with the same auth/admin middleware used by /admin.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue