Moved auth for admin to middleware
continuous-integration/drone/push Build is passing
Details
continuous-integration/drone/push Build is passing
Details
This commit is contained in:
parent
a4955be200
commit
11acd8e277
|
@ -34,11 +34,6 @@ func (h *Handler) ReadAll(c echo.Context) error {
|
|||
}
|
||||
|
||||
func (h *Handler) Create(c echo.Context) error {
|
||||
|
||||
if !isLoggedIn(c) {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "Login first.")
|
||||
}
|
||||
|
||||
str := h.str()
|
||||
if err := c.Bind(str); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||
|
@ -53,10 +48,6 @@ func (h *Handler) Create(c echo.Context) error {
|
|||
}
|
||||
|
||||
func (h *Handler) Delete(c echo.Context) error {
|
||||
if !isLoggedIn(c) {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "Login first.")
|
||||
}
|
||||
|
||||
str := h.str()
|
||||
if err := c.Bind(str); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||
|
@ -71,10 +62,6 @@ func (h *Handler) Delete(c echo.Context) error {
|
|||
}
|
||||
|
||||
func (h *Handler) Update(c echo.Context) error {
|
||||
if !isLoggedIn(c) {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "Login first.")
|
||||
}
|
||||
|
||||
str := h.str()
|
||||
if err := c.Bind(str); err != nil {
|
||||
return echo.NewHTTPError(http.StatusBadRequest, err.Error())
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/labstack/echo/v4"
|
||||
"github.com/labstack/echo/v4/middleware"
|
||||
"html/template"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
func NewEcho() *echo.Echo {
|
||||
|
@ -61,7 +62,15 @@ func RegisterRoutes(e *echo.Echo) {
|
|||
}
|
||||
|
||||
e.GET("/list", handler.ReadAll)
|
||||
// Routes with auth -> TODO: build a middleware which checks this
|
||||
// Routes with auth
|
||||
e.Use(func(next echo.HandlerFunc) echo.HandlerFunc {
|
||||
return func(c echo.Context) error {
|
||||
if !isLoggedIn(c) {
|
||||
return echo.NewHTTPError(http.StatusForbidden, "Login first.")
|
||||
}
|
||||
return next(c)
|
||||
}
|
||||
})
|
||||
e.POST("/update", handler.Update)
|
||||
e.POST("/delete", handler.Delete)
|
||||
e.POST("/add", handler.Create)
|
||||
|
|
Loading…
Reference in New Issue