summaryrefslogtreecommitdiff
path: root/pages/login.go
diff options
context:
space:
mode:
Diffstat (limited to 'pages/login.go')
-rw-r--r--pages/login.go36
1 files changed, 16 insertions, 20 deletions
diff --git a/pages/login.go b/pages/login.go
index bd1ab46..c781f3c 100644
--- a/pages/login.go
+++ b/pages/login.go
@@ -16,27 +16,11 @@ import (
"golang.org/x/crypto/bcrypt"
)
-type userContextKey struct{}
-
-func getUser(ctx context.Context) model.User {
- return ctx.Value(userContextKey{}).(model.User)
-}
-
const (
sessionDuration = 86400 * 7 // 7 days
loginQueryMarker = "next"
)
-func setUserInContext(ctx context.Context, uid int32) (context.Context, error) {
- u, err := Q.GetUserById(ctx, uid)
- if err != nil {
- return ctx, err
- }
-
- u.Pwd = "" // don't carry pwd around
- return context.WithValue(ctx, userContextKey{}, u), nil
-}
-
func RequireAuth(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
s := session.From(r)
@@ -78,7 +62,7 @@ func Login() Page {
}
u := user{}
u.SetCsrfField(r)
- showLoginPage(r, w, u)
+ render(login(u))(w, r)
})
r.Post("/", handleLogin)
@@ -116,7 +100,7 @@ func handleLogin(w http.ResponseWriter, r *http.Request) {
if !ok {
u.AddError("Password", "Username oder Passwort falsch.")
- showLoginPage(r, w, u)
+ render(login(u))(w, r)
return
}
@@ -139,6 +123,18 @@ func handleLogin(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, next, http.StatusFound)
}
-func showLoginPage(r *http.Request, w http.ResponseWriter, u user) {
- render(login(u))(w, r)
+type userContextKey struct{}
+
+func getUser(ctx context.Context) model.User {
+ return ctx.Value(userContextKey{}).(model.User)
+}
+
+func setUserInContext(ctx context.Context, uid int32) (context.Context, error) {
+ u, err := Q.GetUserById(ctx, uid)
+ if err != nil {
+ return ctx, err
+ }
+
+ u.Pwd = "" // don't carry pwd around
+ return context.WithValue(ctx, userContextKey{}, u), nil
}