forked from Deuxfleurs/guichet
Prettier message when wrong username or password on login
This commit is contained in:
parent
b3d6854d82
commit
721eda63f8
2 changed files with 19 additions and 4 deletions
17
main.go
17
main.go
|
@ -309,6 +309,8 @@ func handleLogout(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
type LoginFormData struct {
|
type LoginFormData struct {
|
||||||
Username string
|
Username string
|
||||||
|
WrongUser bool
|
||||||
|
WrongPass bool
|
||||||
ErrorMessage string
|
ErrorMessage string
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -335,10 +337,17 @@ func handleLogin(w http.ResponseWriter, r *http.Request) *LoginInfo {
|
||||||
|
|
||||||
err := l.Bind(user_dn, password)
|
err := l.Bind(user_dn, password)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
templateLogin.Execute(w, LoginFormData{
|
data := &LoginFormData{
|
||||||
Username: username,
|
Username: username,
|
||||||
ErrorMessage: err.Error(),
|
}
|
||||||
})
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,6 +4,12 @@
|
||||||
<h4>S'identifier</h4>
|
<h4>S'identifier</h4>
|
||||||
|
|
||||||
<form method="POST">
|
<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}}
|
{{if .ErrorMessage}}
|
||||||
<div class="alert alert-danger">Impossible de se connecter.
|
<div class="alert alert-danger">Impossible de se connecter.
|
||||||
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div>
|
<div style="font-size: 0.8em">{{ .ErrorMessage }}</div>
|
||||||
|
|
Loading…
Reference in a new issue