mirror of
https://github.com/rjNemo/rentease.git
synced 2026-06-12 13:46:51 +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
|
package constant
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
RouteLogin = "/"
|
||||||
RouteBooking = "/bookings"
|
RouteBooking = "/bookings"
|
||||||
RouteReports = "/reports"
|
RouteReports = "/reports"
|
||||||
RouteItem = "/items"
|
RouteItem = "/items"
|
||||||
|
|
|
||||||
|
|
@ -6,23 +6,20 @@ import (
|
||||||
|
|
||||||
"github.com/labstack/echo-contrib/session"
|
"github.com/labstack/echo-contrib/session"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
)
|
|
||||||
|
|
||||||
const (
|
"github.com/rjNemo/rentease/constant"
|
||||||
cookieName = "rentuuid"
|
|
||||||
routeLogin = "/"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func MakeAuthMiddleware() echo.MiddlewareFunc {
|
func MakeAuthMiddleware() echo.MiddlewareFunc {
|
||||||
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
return func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||||
return func(c echo.Context) error {
|
return func(c echo.Context) error {
|
||||||
if c.Request().RequestURI == routeLogin {
|
if c.Request().RequestURI == constant.RouteLogin {
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
|
|
||||||
s, err := readSession(c)
|
s, err := readSession(c)
|
||||||
if s != "bar" || err != nil {
|
if s != "bar" || err != nil {
|
||||||
return c.Redirect(http.StatusSeeOther, routeLogin)
|
return c.Redirect(http.StatusSeeOther, constant.RouteLogin)
|
||||||
}
|
}
|
||||||
return next(c)
|
return next(c)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import (
|
||||||
"github.com/labstack/echo-contrib/session"
|
"github.com/labstack/echo-contrib/session"
|
||||||
"github.com/labstack/echo/v4"
|
"github.com/labstack/echo/v4"
|
||||||
|
|
||||||
|
"github.com/rjNemo/rentease/constant"
|
||||||
"github.com/rjNemo/rentease/internal/auth"
|
"github.com/rjNemo/rentease/internal/auth"
|
||||||
"github.com/rjNemo/rentease/internal/view"
|
"github.com/rjNemo/rentease/internal/view"
|
||||||
)
|
)
|
||||||
|
|
@ -29,7 +30,7 @@ func handleLogin(as *auth.Service) echo.HandlerFunc {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
sess.Options = &sessions.Options{
|
sess.Options = &sessions.Options{
|
||||||
Path: "/",
|
Path: constant.RouteLogin,
|
||||||
MaxAge: sessionAge,
|
MaxAge: sessionAge,
|
||||||
HttpOnly: true,
|
HttpOnly: true,
|
||||||
}
|
}
|
||||||
|
|
@ -50,6 +51,6 @@ func handleLogin(as *auth.Service) echo.HandlerFunc {
|
||||||
if err := sess.Save(c.Request(), c.Response()); err != nil {
|
if err := sess.Save(c.Request(), c.Response()); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return hxRedirect(c, http.StatusOK, "/bookings")
|
return hxRedirect(c, http.StatusOK, constant.RouteBooking)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue