Skip to content

Commit

Permalink
Add better authentication error messages
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas-bouvier committed Jan 7, 2020
1 parent 01d80cd commit 4c0e7e1
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions loginController.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ func LoginAssociationController(w http.ResponseWriter, r *http.Request) {
if err != nil {
w.WriteHeader(http.StatusUnauthorized)
json.NewEncoder(w).Encode(bson.M{
"error": "failed to authenticate",
"error": fmt.Sprintf("failed to authenticate: %s", err.Error()),
})

return
Expand Down Expand Up @@ -208,13 +208,21 @@ func checkLoginForAssociation(login AssociationLogin) (*AssociationUser, error)
db := session.DB("insapp").C("association_user")

var result AssociationUser
err := db.Find(bson.M{
err1 := db.Find(bson.M{
"username": login.Username,
}).One(&result)

if err1 != nil {
return nil, errors.New("unknown user")
}

err2 := db.Find(bson.M{
"username": login.Username,
"password": GetMD5Hash(login.Password),
}).One(&result)

if err != nil {
return nil, err
if err2 != nil {
return nil, errors.New("wrong password")
}

return &result, nil
Expand Down

0 comments on commit 4c0e7e1

Please sign in to comment.