use constants

This commit is contained in:
Ruidy 2024-06-20 18:34:57 +02:00
parent ae233e46e0
commit ba950f3b03
No known key found for this signature in database
GPG key ID: E00F51288CB857CC
3 changed files with 7 additions and 8 deletions

View file

@ -1,6 +1,7 @@
package constant
const (
RouteLogin = "/"
RouteBooking = "/bookings"
RouteReports = "/reports"
RouteItem = "/items"

View file

@ -6,23 +6,20 @@ import (
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
)
const (
cookieName = "rentuuid"
routeLogin = "/"
"github.com/rjNemo/rentease/constant"
)
func MakeAuthMiddleware() echo.MiddlewareFunc {
return func(next echo.HandlerFunc) echo.HandlerFunc {
return func(c echo.Context) error {
if c.Request().RequestURI == routeLogin {
if c.Request().RequestURI == constant.RouteLogin {
return next(c)
}
s, err := readSession(c)
if s != "bar" || err != nil {
return c.Redirect(http.StatusSeeOther, routeLogin)
return c.Redirect(http.StatusSeeOther, constant.RouteLogin)
}
return next(c)
}

View file

@ -7,6 +7,7 @@ import (
"github.com/labstack/echo-contrib/session"
"github.com/labstack/echo/v4"
"github.com/rjNemo/rentease/constant"
"github.com/rjNemo/rentease/internal/auth"
"github.com/rjNemo/rentease/internal/view"
)
@ -29,7 +30,7 @@ func handleLogin(as *auth.Service) echo.HandlerFunc {
return err
}
sess.Options = &sessions.Options{
Path: "/",
Path: constant.RouteLogin,
MaxAge: sessionAge,
HttpOnly: true,
}
@ -50,6 +51,6 @@ func handleLogin(as *auth.Service) echo.HandlerFunc {
if err := sess.Save(c.Request(), c.Response()); err != nil {
return err
}
return hxRedirect(c, http.StatusOK, "/bookings")
return hxRedirect(c, http.StatusOK, constant.RouteBooking)
}
}