diff options
author | Emile <hanemile@protonmail.com> | 2019-10-07 11:50:14 +0200 |
---|---|---|
committer | Emile <hanemile@protonmail.com> | 2019-10-07 11:50:14 +0200 |
commit | e411dbbed4a5e7199cb95e527255e2c793f6b140 (patch) | |
tree | 4489028f2731cfb988dc757a233e734c3325e8f3 /src | |
parent | acd34f9801893766a2eabb09a2f4bae21dd1a671 (diff) |
added a redirect to usernameTaken if the username already exists
Diffstat (limited to 'src')
-rw-r--r-- | src/http.go | 10 |
1 files changed, 9 insertions, 1 deletions
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 { |