Prettier message when wrong username or password on login

This commit is contained in:
Alex Auvolat 2020-02-12 16:02:42 +01:00
parent b3d6854d82
commit 721eda63f8
2 changed files with 19 additions and 4 deletions

17
main.go
View File

@ -309,6 +309,8 @@ func handleLogout(w http.ResponseWriter, r *http.Request) {
type LoginFormData struct {
Username string
WrongUser bool
WrongPass bool
ErrorMessage string
}
@ -335,10 +337,17 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
err := l.Bind(user_dn, password)
if err != nil {
templateLogin.Execute(w, LoginFormData{
Username: username,
ErrorMessage: err.Error(),
})
data := &LoginFormData{
Username: username,
}
if ldap.IsErrorWithCode(err, ldap.LDAPResultInvalidCredentials) {
data.WrongPass = true
} else if ldap.IsErrorWithCode(err, ldap.LDAPResultNoSuchObject) {
data.WrongUser = true
} else {
data.ErrorMessage = err.Error()
}
templateLogin.Execute(w, data)
return nil
}

View File

@ -4,6 +4,12 @@
<h4>S'identifier</h4>
<form method="POST">
{{if .WrongUser}}
<div class="alert alert-danger">Nom d'utilisateur invalide.</div>
{{end}}
{{if .WrongPass}}
<div class="alert alert-danger">Mot de passe invalide.</div>
{{end}}
{{if .ErrorMessage}}
<div class="alert alert-danger">Impossible de se connecter.
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div>