diff --git a/internal/webserver/controller/highlight/highlight.go b/internal/webserver/controller/highlight/highlight.go index 427ab3d..e4220f7 100644 --- a/internal/webserver/controller/highlight/highlight.go +++ b/internal/webserver/controller/highlight/highlight.go @@ -2,16 +2,11 @@ package highlight import ( "github.com/gofiber/fiber/v2" - "github.com/svera/coreander/v3/internal/webserver/jwtclaimsreader" + "github.com/svera/coreander/v3/internal/webserver/model" ) func (h *Controller) Highlight(c *fiber.Ctx) error { - session := jwtclaimsreader.SessionData(c) - - user, err := h.usrRepository.FindByUuid(session.Uuid) - if err != nil { - return fiber.ErrBadRequest - } + user := c.Locals("Session").(model.User) document, err := h.idx.Document(c.FormValue("slug")) if err != nil { diff --git a/internal/webserver/controller/highlight/remove.go b/internal/webserver/controller/highlight/remove.go index 418d99f..672ad78 100644 --- a/internal/webserver/controller/highlight/remove.go +++ b/internal/webserver/controller/highlight/remove.go @@ -2,16 +2,11 @@ package highlight import ( "github.com/gofiber/fiber/v2" - "github.com/svera/coreander/v3/internal/webserver/jwtclaimsreader" + "github.com/svera/coreander/v3/internal/webserver/model" ) func (h *Controller) Remove(c *fiber.Ctx) error { - session := jwtclaimsreader.SessionData(c) - - user, err := h.usrRepository.FindByUuid(session.Uuid) - if err != nil { - return fiber.ErrBadRequest - } + user := c.Locals("Session").(model.User) document, err := h.idx.Document(c.FormValue("slug")) if err != nil { diff --git a/internal/webserver/embedded/views/document.html b/internal/webserver/embedded/views/document.html index 2c62ea3..c8b82ef 100644 --- a/internal/webserver/embedded/views/document.html +++ b/internal/webserver/embedded/views/document.html @@ -41,13 +41,14 @@

{{if and (.Session) (ne .Session.Name "")}} - +   {{t .Lang "Highlight"}} - + + diff --git a/internal/webserver/jwtclaimsreader/jwtclaimsreader.go b/internal/webserver/jwtclaimsreader.go similarity index 93% rename from internal/webserver/jwtclaimsreader/jwtclaimsreader.go rename to internal/webserver/jwtclaimsreader.go index 97489f7..72dab38 100644 --- a/internal/webserver/jwtclaimsreader/jwtclaimsreader.go +++ b/internal/webserver/jwtclaimsreader.go @@ -1,4 +1,4 @@ -package jwtclaimsreader +package webserver import ( "github.com/gofiber/fiber/v2" @@ -6,7 +6,7 @@ import ( "github.com/svera/coreander/v3/internal/webserver/model" ) -func SessionData(c *fiber.Ctx) model.User { +func sessionData(c *fiber.Ctx) model.User { var user model.User if t, ok := c.Locals("user").(*jwt.Token); ok { claims := t.Claims.(jwt.MapClaims) diff --git a/internal/webserver/middleware.go b/internal/webserver/middleware.go index 62d96e9..8eeef48 100644 --- a/internal/webserver/middleware.go +++ b/internal/webserver/middleware.go @@ -7,7 +7,6 @@ import ( "github.com/gofiber/fiber/v2" jwtware "github.com/gofiber/jwt/v3" "github.com/svera/coreander/v3/internal/webserver/infrastructure" - "github.com/svera/coreander/v3/internal/webserver/jwtclaimsreader" "github.com/svera/coreander/v3/internal/webserver/model" ) @@ -79,7 +78,7 @@ func AlwaysRequireAuthentication(jwtSecret []byte, sender Sender) func(*fiber.Ct SigningMethod: "HS256", TokenLookup: "cookie:coreander", SuccessHandler: func(c *fiber.Ctx) error { - c.Locals("Session", jwtclaimsreader.SessionData(c)) + c.Locals("Session", sessionData(c)) return c.Next() }, ErrorHandler: func(c *fiber.Ctx, err error) error { @@ -95,7 +94,7 @@ func ConfigurableAuthentication(jwtSecret []byte, sender Sender, requireAuth boo SigningMethod: "HS256", TokenLookup: "cookie:coreander", SuccessHandler: func(c *fiber.Ctx) error { - c.Locals("Session", jwtclaimsreader.SessionData(c)) + c.Locals("Session", sessionData(c)) return c.Next() }, ErrorHandler: func(c *fiber.Ctx, err error) error { diff --git a/internal/webserver/webserver.go b/internal/webserver/webserver.go index 5b06d53..3c14095 100644 --- a/internal/webserver/webserver.go +++ b/internal/webserver/webserver.go @@ -16,7 +16,6 @@ import ( "github.com/svera/coreander/v3/internal/i18n" "github.com/svera/coreander/v3/internal/index" "github.com/svera/coreander/v3/internal/webserver/infrastructure" - "github.com/svera/coreander/v3/internal/webserver/jwtclaimsreader" "golang.org/x/exp/slices" "golang.org/x/text/message" ) @@ -182,7 +181,6 @@ func errorHandler(c *fiber.Ctx, err error) error { fiber.Map{ "Lang": chooseBestLanguage(c), "Title": "Coreander", - "Session": jwtclaimsreader.SessionData(c), "Version": c.App().Config().AppName, }, "layout")