prompt 6
This commit is contained in:
@@ -1,46 +1,54 @@
|
||||
package http
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"trustcontact/internal/config"
|
||||
"trustcontact/internal/controllers"
|
||||
httpmw "trustcontact/internal/http/middleware"
|
||||
"trustcontact/internal/services"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
"github.com/gofiber/fiber/v2/middleware/session"
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
func RegisterRoutes(app *fiber.App, store *session.Store, database *gorm.DB, _ *config.Config) {
|
||||
func RegisterRoutes(app *fiber.App, store *session.Store, database *gorm.DB, cfg *config.Config) error {
|
||||
app.Use(httpmw.SessionStoreMiddleware(store))
|
||||
app.Use(httpmw.CurrentUserMiddleware(store, database))
|
||||
app.Use(httpmw.ConsumeFlash())
|
||||
|
||||
authService, err := services.NewAuthService(database, cfg)
|
||||
if err != nil {
|
||||
return fmt.Errorf("init auth service: %w", err)
|
||||
}
|
||||
authController := controllers.NewAuthController(authService)
|
||||
|
||||
app.Get("/healthz", func(c *fiber.Ctx) error {
|
||||
return c.SendStatus(fiber.StatusOK)
|
||||
})
|
||||
|
||||
app.Get("/", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "public")
|
||||
httpmw.SetTemplateData(c, "NavSection", "public")
|
||||
return c.SendString("public area")
|
||||
})
|
||||
|
||||
app.Get("/login", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "public")
|
||||
httpmw.SetTemplateData(c, "NavSection", "public")
|
||||
return c.SendString("login page")
|
||||
})
|
||||
app.Get("/", authController.ShowHome)
|
||||
app.Get("/signup", authController.ShowSignup)
|
||||
app.Post("/signup", authController.Signup)
|
||||
app.Get("/login", authController.ShowLogin)
|
||||
app.Post("/login", authController.Login)
|
||||
app.Post("/logout", authController.Logout)
|
||||
app.Get("/verify-email", authController.VerifyEmail)
|
||||
app.Get("/verify-notice", authController.ShowVerifyNotice)
|
||||
app.Get("/forgot-password", authController.ShowForgotPassword)
|
||||
app.Post("/forgot-password", authController.ForgotPassword)
|
||||
app.Get("/reset-password", authController.ShowResetPassword)
|
||||
app.Post("/reset-password", authController.ResetPassword)
|
||||
|
||||
private := app.Group("/private", httpmw.RequireAuth())
|
||||
private.Get("/", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "private")
|
||||
httpmw.SetTemplateData(c, "NavSection", "private")
|
||||
return c.SendString("private area")
|
||||
})
|
||||
|
||||
admin := app.Group("/admin", httpmw.RequireAuth(), httpmw.RequireAdmin())
|
||||
admin.Get("/", func(c *fiber.Ctx) error {
|
||||
c.Locals("nav_section", "admin")
|
||||
httpmw.SetTemplateData(c, "NavSection", "admin")
|
||||
return c.SendString("admin area")
|
||||
})
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user