diff options
author | Alex Auvolat <alex@adnab.me> | 2020-02-12 16:02:42 +0100 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-02-12 16:02:42 +0100 |
commit | 721eda63f8734a93cc10c2c36a4c274d2142e66c (patch) | |
tree | 5b7063b90fdc0c29158eefc8de6e016c4c8c6014 /main.go | |
parent | b3d6854d82143ef62234a408ada01d4035c19b20 (diff) | |
download | guichet-721eda63f8734a93cc10c2c36a4c274d2142e66c.tar.gz guichet-721eda63f8734a93cc10c2c36a4c274d2142e66c.zip |
Prettier message when wrong username or password on login
Diffstat (limited to 'main.go')
-rw-r--r-- | main.go | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -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 } |