aggiunto e testato quasar apps
This commit is contained in:
@@ -1,49 +1,27 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"html/template"
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type AdminController struct{}
|
||||
type AdminController struct {
|
||||
spaDir string
|
||||
}
|
||||
|
||||
func NewAdminController() *AdminController {
|
||||
return &AdminController{}
|
||||
func NewAdminController(spaDir string) *AdminController {
|
||||
return &AdminController{spaDir: spaDir}
|
||||
}
|
||||
|
||||
func (ac *AdminController) Dashboard(c *fiber.Ctx) error {
|
||||
return renderAdminPage(c, "Admin")
|
||||
return c.SendFile(filepath.Join(ac.spaDir, "index.html"))
|
||||
}
|
||||
|
||||
func renderAdminPage(c *fiber.Ctx, title string) error {
|
||||
viewData := map[string]any{
|
||||
"Title": title,
|
||||
"NavSection": "admin",
|
||||
}
|
||||
for k, v := range localsTemplateData(c) {
|
||||
viewData[k] = v
|
||||
}
|
||||
|
||||
files := []string{
|
||||
"web/templates/layout.html",
|
||||
"web/templates/public/_navbar.html",
|
||||
"web/templates/partials/language_dropdown.html",
|
||||
"web/templates/public/_flash.html",
|
||||
"web/templates/admin/admin.html",
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(files...)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
var out bytes.Buffer
|
||||
if err := tmpl.ExecuteTemplate(&out, "layout.html", viewData); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Type("html", "utf-8")
|
||||
return c.Send(out.Bytes())
|
||||
func (ac *AdminController) Fallback(c *fiber.Ctx) error {
|
||||
return c.SendFile(filepath.Join(ac.spaDir, "index.html"))
|
||||
}
|
||||
|
||||
func (ac *AdminController) Favicon(c *fiber.Ctx) error {
|
||||
return c.SendFile(filepath.Join(ac.spaDir, "favicon.ico"))
|
||||
}
|
||||
|
||||
@@ -25,13 +25,6 @@ func (ac *AuthController) ShowHome(c *fiber.Ctx) error {
|
||||
})
|
||||
}
|
||||
|
||||
func (ac *AuthController) ShowWelcome(c *fiber.Ctx) error {
|
||||
return renderPrivate(c, "welcome.html", map[string]any{
|
||||
"Title": "Welcome",
|
||||
"NavSection": "private",
|
||||
})
|
||||
}
|
||||
|
||||
func (ac *AuthController) ShowSignup(c *fiber.Ctx) error {
|
||||
return renderPublic(c, "signup.html", map[string]any{
|
||||
"Title": "Sign up",
|
||||
@@ -97,7 +90,7 @@ func (ac *AuthController) Login(c *fiber.Ctx) error {
|
||||
if err := httpmw.SetFlashSuccess(c, "Login effettuato"); err != nil {
|
||||
return err
|
||||
}
|
||||
return c.Redirect("/welcome")
|
||||
return c.Redirect("/private")
|
||||
}
|
||||
|
||||
func (ac *AuthController) Logout(c *fiber.Ctx) error {
|
||||
|
||||
27
internal/controllers/private_controller.go
Normal file
27
internal/controllers/private_controller.go
Normal file
@@ -0,0 +1,27 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type PrivateController struct {
|
||||
spaDir string
|
||||
}
|
||||
|
||||
func NewPrivateController(spaDir string) *PrivateController {
|
||||
return &PrivateController{spaDir: spaDir}
|
||||
}
|
||||
|
||||
func (ac *PrivateController) Dashboard(c *fiber.Ctx) error {
|
||||
return c.SendFile(filepath.Join(ac.spaDir, "index.html"))
|
||||
}
|
||||
|
||||
func (ac *PrivateController) Fallback(c *fiber.Ctx) error {
|
||||
return c.SendFile(filepath.Join(ac.spaDir, "index.html"))
|
||||
}
|
||||
|
||||
func (ac *PrivateController) Favicon(c *fiber.Ctx) error {
|
||||
return c.SendFile(filepath.Join(ac.spaDir, "favicon.ico"))
|
||||
}
|
||||
@@ -1,27 +0,0 @@
|
||||
package controllers
|
||||
|
||||
import (
|
||||
"trustcontact/internal/services"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
)
|
||||
|
||||
type UsersController struct {
|
||||
usersService *services.UsersService
|
||||
}
|
||||
|
||||
func NewUsersController(usersService *services.UsersService) *UsersController {
|
||||
return &UsersController{usersService: usersService}
|
||||
}
|
||||
|
||||
func (uc *UsersController) Index(c *fiber.Ctx) error {
|
||||
return renderAdminPage(c, "Admin")
|
||||
}
|
||||
|
||||
func (uc *UsersController) Table(c *fiber.Ctx) error {
|
||||
return renderAdminPage(c, "Admin")
|
||||
}
|
||||
|
||||
func (uc *UsersController) Modal(c *fiber.Ctx) error {
|
||||
return renderAdminPage(c, "Admin")
|
||||
}
|
||||
Reference in New Issue
Block a user