summaryrefslogtreecommitdiff
path: root/pages/login.go
diff options
context:
space:
mode:
Diffstat (limited to 'pages/login.go')
-rw-r--r--pages/login.go9
1 files changed, 5 insertions, 4 deletions
diff --git a/pages/login.go b/pages/login.go
index 14b1ce1..84119e9 100644
--- a/pages/login.go
+++ b/pages/login.go
@@ -6,6 +6,7 @@ import (
"errors"
"gosten/csrf"
"gosten/form"
+ "gosten/model"
"gosten/session"
"log"
"net/http"
@@ -17,8 +18,8 @@ import (
type userContextKey struct{}
-func userId(r *http.Request) int32 {
- return r.Context().Value(userContextKey{}).(int32)
+func getUser(ctx context.Context) model.User {
+ return ctx.Value(userContextKey{}).(model.User)
}
const (
@@ -34,7 +35,7 @@ func RequireAuth(next http.Handler) http.Handler {
u, err := Q.GetUserById(r.Context(), s.UserID)
if err == nil {
// authenticated --> done
- ctx := context.WithValue(r.Context(), userContextKey{}, u.ID)
+ ctx := context.WithValue(r.Context(), userContextKey{}, u)
next.ServeHTTP(w, r.WithContext(ctx))
return
}
@@ -126,5 +127,5 @@ func handleLogin(w http.ResponseWriter, r *http.Request) {
}
func showLoginPage(r *http.Request, w http.ResponseWriter, u user) {
- render(login(u), w, r)
+ render(login(u))(w, r)
}