Skip to content

Commit 4b6c992

Browse files
authored
Merge pull request #52 from arran4/codex/fix-signup-and-login-error-handling
Fix local git auth feedback and logging
2 parents 5a313a8 + 669baad commit 4b6c992

File tree

4 files changed

+24
-1
lines changed

4 files changed

+24
-1
lines changed

authHandlers.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,13 @@ func GitLoginAction(w http.ResponseWriter, r *http.Request) error {
156156
return fmt.Errorf("password handler not available")
157157
}
158158
okPass, err := ph.CheckPassword(r.Context(), user, pass)
159+
if err != nil {
160+
log.Printf("git login check error for %s: %v", user, err)
161+
}
159162
if err != nil || !okPass {
163+
if !okPass {
164+
log.Printf("git login failed for %s: invalid password", user)
165+
}
160166
http.Redirect(w, r, "/login/git?error=invalid", http.StatusSeeOther)
161167
return nil
162168
}
@@ -180,15 +186,19 @@ func GitSignupAction(w http.ResponseWriter, r *http.Request) error {
180186
}
181187
if err := ph.CreateUser(r.Context(), user, pass); err != nil {
182188
if errors.Is(err, ErrUserExists) {
189+
log.Printf("git signup for %s failed: user exists", user)
183190
http.Redirect(w, r, "/login/git?error=exists", http.StatusSeeOther)
184191
return nil
185192
}
193+
log.Printf("git signup create user error for %s: %v", user, err)
186194
return err
187195
}
188196
if err := prov.CreateRepo(r.Context(), user, nil, RepoName); err != nil {
197+
log.Printf("git signup create repo error for %s: %v", user, err)
189198
return err
190199
}
191200
if err := prov.CreateBookmarks(r.Context(), user, nil, "main", defaultBookmarks); err != nil {
201+
log.Printf("git signup create sample bookmarks error for %s: %v", user, err)
192202
return fmt.Errorf("create sample bookmarks: %w", err)
193203
}
194204
return nil

data_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ func testFuncMap() template.FuncMap {
4646
"Providers": func() []string { return []string{"github", "gitlab"} },
4747
"AllProviders": func() []string { return []string{"github", "gitlab"} },
4848
"ProviderConfigured": func(string) bool { return true },
49+
"errorMsg": func(s string) string { return s },
4950
"ref": func() string { return "refs/heads/main" },
5051
"add1": func(i int) int { return i + 1 },
5152
"tab": func() string { return "" },

funcs.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ func NewFuncs(r *http.Request) template.FuncMap {
7070
creds := providerCreds(p)
7171
return creds != nil && GetProvider(p) != nil
7272
},
73+
"errorMsg": errorMessage,
7374
"ref": func() string {
7475
return r.URL.Query().Get("ref")
7576
},
@@ -329,3 +330,14 @@ func BookmarksExist(r *http.Request) (bool, error) {
329330
}
330331
return bookmarks != "", nil
331332
}
333+
334+
func errorMessage(code string) string {
335+
switch code {
336+
case "invalid":
337+
return "Invalid username or password"
338+
case "exists":
339+
return "Account already exists"
340+
default:
341+
return code
342+
}
343+
}

templates/gitLoginPage.gohtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{{ template "head" $ }}
22
<form method="POST" action="/login/git">
3-
{{- if .Error }}<p style="color:red">{{ .Error }}</p>{{ end }}
3+
{{- if .Error }}<p style="color:red">{{ errorMsg .Error }}</p>{{ end }}
44
Username: <input type="text" name="username"><br>
55
Password: <input type="password" name="password"><br>
66
<input type="submit" value="Login">

0 commit comments

Comments
 (0)