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 ++++++++++++---- templates/login.tmpl | 2 ++ 2 files changed, 14 insertions(+), 4 deletions(-) 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, ""}) } } diff --git a/templates/login.tmpl b/templates/login.tmpl index 6f76a4a..a78fdc1 100644 --- a/templates/login.tmpl +++ b/templates/login.tmpl @@ -9,6 +9,7 @@ body{margin: 0 auto; width: 400px; padding-top: 10em; font-family: "Source Sans form > hr{border: none; border-top: 1px solid #e6e6e6; margin: 1.3em 0;} form > h4{font-weight: 300; font-size: 19px; margin-bottom: 0} label {font-weight: bold; text-align: right;} form > div {display: grid; grid-template-columns: 2fr 5fr; grid-gap: 1em 1em; align-items: center;} +form .alert { background-color: #ff0039; grid-column: 1 / 3; color: white; padding: 0.8em 1em} input, button {font-size: inherit; font-family: inherit; line-height: inherit; padding: 0.8em 1em; border-radius: 0} input {border: 1px solid #cccccc; transition: border-color ease-in-out .15s,box-shadow ease-in-out .15s} input:focus {border-color: #66afe9; outline: 0; box-shadow: inset 0 1px 1px rgba(0,0,0,0.075),0 0 8px rgba(102,175,233,0.6)} @@ -28,6 +29,7 @@ button:hover {background-color: #1967be; border-color: #1862b5} + {{ if .Flash }}
{{.Flash}}
{{end}} -- cgit v1.2.3-70-g09d2