mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-10 04:36:50 +00:00
use constants
This commit is contained in:
parent
ae233e46e0
commit
ba950f3b03
3 changed files with 7 additions and 8 deletions
|
|
@ -1,6 +1,7 @@
|
|||
package constant
|
||||
|
||||
const (
|
||||
RouteLogin = "/"
|
||||
RouteBooking = "/bookings"
|
||||
RouteReports = "/reports"
|
||||
RouteItem = "/items"
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue