From e411dbbed4a5e7199cb95e527255e2c793f6b140 Mon Sep 17 00:00:00 2001 From: Emile Date: Mon, 7 Oct 2019 11:50:14 +0200 Subject: added a redirect to usernameTaken if the username already exists --- src/http.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/http.go b/src/http.go index a9b4240..5ed4957 100644 --- a/src/http.go +++ b/src/http.go @@ -4,6 +4,7 @@ import ( "flag" "fmt" "io/ioutil" + "log" "net/http" "strings" @@ -50,7 +51,8 @@ func registerPostHandler(w http.ResponseWriter, r *http.Request) { // test if the username has already been chosen if !isUniq(username) { - w.Write([]byte("Username has already been taken.")) + log.Println("redirecting to usernameTaken") + usernameTakenGetHandler(w, r) return } @@ -59,11 +61,17 @@ func registerPostHandler(w http.ResponseWriter, r *http.Request) { // generate a new accesscode accesscode := newAccessCode() + log.Printf("Generated a new AccessCode for user %s: %s", username, accesscode) // redirect the user to the front page http.Redirect(w, r, "/", http.StatusTemporaryRedirect) } +func usernameTakenGetHandler(w http.ResponseWriter, r *http.Request) { + log.Println("[usernameTaken]") + readFileToReponse(w, "/usernameTaken.html") +} + func isUniq(username string) bool { for _, user := range usernames { if username == user { -- cgit 1.4.1