aboutsummaryrefslogtreecommitdiff
path: root/pkg/ext
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/ext')
-rw-r--r--pkg/ext/middleware.go10
-rw-r--r--pkg/ext/responses.go2
2 files changed, 6 insertions, 6 deletions
diff --git a/pkg/ext/middleware.go b/pkg/ext/middleware.go
index fe2d185..2cf70cf 100644
--- a/pkg/ext/middleware.go
+++ b/pkg/ext/middleware.go
@@ -56,7 +56,7 @@ func NewAuthMiddleware(key []byte, log *logrus.Entry) *AuthMiddleware {
func (a *AuthMiddleware) LoggedIn(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
- path := string(r.URL.Path)
+ path := r.URL.Path
if path == "/login" || path == "/initial" {
next(w, r)
return
@@ -82,7 +82,7 @@ func (a *AuthMiddleware) LoggedIn(next http.HandlerFunc) http.HandlerFunc {
http.Redirect(w, r, redirectLogin, http.StatusTemporaryRedirect)
return
}
- r = r.WithContext(context.WithValue(r.Context(), "token", token))
+ r = r.WithContext(context.WithValue(r.Context(), service.TokenKey, token))
a.entry.
WithField("userID", token.UserID).
WithField("username", token.Username).
@@ -91,8 +91,8 @@ func (a *AuthMiddleware) LoggedIn(next http.HandlerFunc) http.HandlerFunc {
}
}
-func GetTokenFromCtx(w http.ResponseWriter, r *http.Request) *service.Token {
- tokenValue := r.Context().Value("token")
+func GetTokenFromCtx(r *http.Request) *service.Token {
+ tokenValue := r.Context().Value(service.TokenKey)
if token, ok := tokenValue.(*service.Token); ok {
return token
}
@@ -112,7 +112,7 @@ func NewInitialSetupMiddleware(userRepository repository.UserRepository) *Initia
func (i *InitialSetupMiddleware) Check(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
// if user has been set to context it is logged in already
- token := GetTokenFromCtx(w, r)
+ token := GetTokenFromCtx(r)
if token == nil {
next(w, r)
return
diff --git a/pkg/ext/responses.go b/pkg/ext/responses.go
index ba58dd5..34e5f27 100644
--- a/pkg/ext/responses.go
+++ b/pkg/ext/responses.go
@@ -7,7 +7,7 @@ import (
"git.sr.ht/~gabrielgio/img/templates"
)
-func NotFound(w http.ResponseWriter, r *http.Request) {
+func NotFound(w http.ResponseWriter) {
templates.WritePageTemplate(w, &templates.ErrorPage{
Err: "Not Found",
})