Login with bad credentials fails correctly

Signed-off-by: James Ketrenos <james_git@ketrenos.com>
This commit is contained in:
James Ketr 2018-09-16 21:06:38 -07:00
parent c2ae12df5c
commit 3c4d12c176
2 changed files with 16 additions and 3 deletions

View File

@ -506,10 +506,21 @@
return;
}
this.loading = true;
this.user = null;
window.fetch("api/v1/users/login", function(error, xhr) {
this.loading = false;
this.password = "";
var user;
if (error) {
this.user = null;
this.$.toast.text = error;
this.$.toast.setAttribute("error", true);
this.$.toast.updateStyles();
this.$.toast.show();
console.error("Invalid login information.");
return;
}
try {
user = JSON.parse(xhr.responseText);
} catch(___) {
@ -518,7 +529,9 @@
this.$.toast.updateStyles();
this.$.toast.show();
console.error("Unable to parse user information");
return;
}
this.user = user;
}.bind(this), null, "POST", { u: this.username, p: this.password });
},

View File

@ -49,7 +49,7 @@ router.post("/login", function(req, res) {
return ldapPromise(username, password).then(function(user) {
return user;
}).catch(function() {
let query = "SELECT * FROM users WHERE username=:username";
let query = "SELECT * FROM users WHERE uid=:username";
return userDB.sequelize.query(query, {
replacements: {
username: username,
@ -64,13 +64,13 @@ router.post("/login", function(req, res) {
});
}).then(function(user) {
if (!user) {
console.log(username + " not found: " + error);
console.log(username + " not found.");
req.session.user = {};
return res.status(401).send("Invalid login credentials");
}
console.log("Logging in as " + user.displayName);
req.session.user = {
name: user.displayName,
mail: user.mail,