chore(web): use web auth factory directly
(cherry picked from commit 9b01666ec6c41f5487cfc6c381b3937f1fe53a16)
This commit is contained in:
@ -17,13 +17,11 @@
|
||||
package handler
|
||||
|
||||
import (
|
||||
"code.vikunja.io/api/pkg/web"
|
||||
"github.com/op/go-logging"
|
||||
)
|
||||
|
||||
// Config contains the config for the web handler
|
||||
type Config struct {
|
||||
AuthProvider *web.Auths
|
||||
LoggingProvider *logging.Logger
|
||||
}
|
||||
|
||||
@ -33,11 +31,6 @@ func init() {
|
||||
config = &Config{}
|
||||
}
|
||||
|
||||
// SetAuthProvider sets the auth provider in config
|
||||
func SetAuthProvider(provider *web.Auths) {
|
||||
config.AuthProvider = provider
|
||||
}
|
||||
|
||||
// SetLoggingProvider sets the logging provider in the config
|
||||
func SetLoggingProvider(logger *logging.Logger) {
|
||||
config.LoggingProvider = logger
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -47,7 +48,7 @@ func (c *WebHandler) CreateWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Get the user to pass for later checks
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -47,7 +48,7 @@ func (c *WebHandler) DeleteWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Check if the user has the right to delete
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError)
|
||||
}
|
||||
|
@ -25,6 +25,7 @@ import (
|
||||
|
||||
vconfig "code.vikunja.io/api/pkg/config"
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -34,7 +35,7 @@ func (c *WebHandler) ReadAllWeb(ctx echo.Context) error {
|
||||
// Get our model
|
||||
currentStruct := c.EmptyStruct()
|
||||
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
@ -23,6 +23,7 @@ import (
|
||||
"strconv"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -43,7 +44,7 @@ func (c *WebHandler) ReadOneWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Check rights
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
@ -22,6 +22,7 @@ import (
|
||||
"net/http"
|
||||
|
||||
"code.vikunja.io/api/pkg/db"
|
||||
"code.vikunja.io/api/pkg/modules/auth"
|
||||
|
||||
"github.com/labstack/echo/v4"
|
||||
)
|
||||
@ -48,7 +49,7 @@ func (c *WebHandler) UpdateWeb(ctx echo.Context) error {
|
||||
}
|
||||
|
||||
// Check if the user has the right to do that
|
||||
currentAuth, err := config.AuthProvider.AuthObject(ctx)
|
||||
currentAuth, err := auth.GetAuthFromClaims(ctx)
|
||||
if err != nil {
|
||||
return echo.NewHTTPError(http.StatusInternalServerError, "Could not determine the current user.")
|
||||
}
|
||||
|
Reference in New Issue
Block a user