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
15
main.go
15
main.go
|
@ -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{
|
||||
data := &LoginFormData{
|
||||
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
|
||||
}
|
||||
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue