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; return;
} }
this.loading = true; this.loading = true;
this.user = null;
window.fetch("api/v1/users/login", function(error, xhr) { window.fetch("api/v1/users/login", function(error, xhr) {
this.loading = false; this.loading = false;
this.password = ""; this.password = "";
var user; 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 { try {
user = JSON.parse(xhr.responseText); user = JSON.parse(xhr.responseText);
} catch(___) { } catch(___) {
@ -518,7 +529,9 @@
this.$.toast.updateStyles(); this.$.toast.updateStyles();
this.$.toast.show(); this.$.toast.show();
console.error("Unable to parse user information"); console.error("Unable to parse user information");
return;
} }
this.user = user; this.user = user;
}.bind(this), null, "POST", { u: this.username, p: this.password }); }.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 ldapPromise(username, password).then(function(user) {
return user; return user;
}).catch(function() { }).catch(function() {
let query = "SELECT * FROM users WHERE username=:username"; let query = "SELECT * FROM users WHERE uid=:username";
return userDB.sequelize.query(query, { return userDB.sequelize.query(query, {
replacements: { replacements: {
username: username, username: username,
@ -64,7 +64,7 @@ router.post("/login", function(req, res) {
}); });
}).then(function(user) { }).then(function(user) {
if (!user) { if (!user) {
console.log(username + " not found: " + error); console.log(username + " not found.");
req.session.user = {}; req.session.user = {};
return res.status(401).send("Invalid login credentials"); return res.status(401).send("Invalid login credentials");
} }