log auth errors
This commit is contained in:
parent
feb3973869
commit
63da748c1b
|
@ -34,6 +34,7 @@ func requestAuth(w http.ResponseWriter, status int) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func LoginHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
func LoginHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params) {
|
||||||
|
|
||||||
err := req.ParseForm()
|
err := req.ParseForm()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
|
||||||
|
@ -52,12 +53,15 @@ func LoginHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := user.Login(password); err != nil {
|
if err := user.Login(password); err != nil {
|
||||||
|
|
||||||
code := http.StatusBadRequest
|
code := http.StatusBadRequest
|
||||||
status := http.StatusText(code)
|
status := http.StatusText(code)
|
||||||
if err, ok := err.(errors.InvalidCredentials); ok {
|
if err, ok := err.(*errors.InvalidCredentials); ok {
|
||||||
code = err.Code()
|
code = err.Code()
|
||||||
status = err.Error()
|
status = err.Error()
|
||||||
err.Log()
|
err.Log()
|
||||||
|
} else {
|
||||||
|
logrus.Errorf("could not login %s: %s", username, err.Error())
|
||||||
}
|
}
|
||||||
http.Error(w, status, code)
|
http.Error(w, status, code)
|
||||||
return
|
return
|
||||||
|
@ -65,7 +69,9 @@ func LoginHandler(w http.ResponseWriter, req *http.Request, ps httprouter.Params
|
||||||
|
|
||||||
sess, err := NewSession(user, _db.Collection("session"))
|
sess, err := NewSession(user, _db.Collection("session"))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(w, fmt.Sprintf("Could not create a session: %s", err), http.StatusInternalServerError)
|
err = fmt.Errorf("Could not create a session: %s", err)
|
||||||
|
logrus.Error(err)
|
||||||
|
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue