From 6ae97fe4d7c4fa1c80571d41c356453199041067 Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Mon, 31 Dec 2018 06:43:36 -0500 Subject: Add error messages in login page --- main.go | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 34667cf..86fd969 100644 --- a/main.go +++ b/main.go @@ -75,15 +75,23 @@ func (app *App) loginHandler(w http.ResponseWriter, r *http.Request) { http.SetCookie(w, &c) http.Redirect(w, r, next, http.StatusSeeOther) } else { + var flash string + if !ok { + flash = "Utilisateur non enregistré" + } else if subtle.ConstantTimeCompare(u.Password, hash) != 1 { + flash = "Mot de passe incorrect" + } app.Template.ExecuteTemplate(w, "login.tmpl", struct { - Next string - }{next}) + Next string + Flash string + }{next, flash}) } } else if r.Method == http.MethodGet { next := r.FormValue("next") app.Template.ExecuteTemplate(w, "login.tmpl", struct { - Next string - }{next}) + Next string + Flash string + }{next, ""}) } } -- cgit v1.2.3-70-g09d2