Enabled authtentication by email address
This commit is contained in:
parent
f7ff1bbb37
commit
68cc758ab1
|
@ -9,7 +9,7 @@ block content
|
|||
| Username or password incorrect. Please try again.
|
||||
form(method="POST", action=getUrl("loginTarget"))
|
||||
.form-group
|
||||
input.form-control(type="text", name="username", placeholder="Username", autofocus)
|
||||
input.form-control(type="text", name="username", placeholder="Username or email", autofocus)
|
||||
.form-group
|
||||
input.form-control(type="password", name="password", placeholder="Password")
|
||||
.form-group
|
||||
|
|
|
@ -48,24 +48,36 @@ module.exports.logout = function(req, res, render) {
|
|||
res.redirect(getUrl("index"));
|
||||
}
|
||||
|
||||
function logUser(user, password, req, res, render) {
|
||||
if (testPassword(password, user.password)) {
|
||||
req.session.user = user;
|
||||
|
||||
let redirection = req.session.redirectAfterLog || 'index';
|
||||
req.session.redirectAfterLog = undefined;
|
||||
req.session.save();
|
||||
|
||||
res.redirect(getUrl(redirection));
|
||||
} else {
|
||||
req.session.loginFailed = true;
|
||||
req.session.save();
|
||||
res.redirect(getUrl('login'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
module.exports.loginTarget = function(req, res, render) {
|
||||
User.getByUsername(req.body.username, (err, user) => {
|
||||
if (user === undefined || !user.active) {
|
||||
res.redirect(getUrl('login'));
|
||||
// Try with email address
|
||||
User.getByEmail(req.body.username, (err, user) => {
|
||||
if (user === undefined || !user.active) {
|
||||
res.redirect(getUrl('login'));
|
||||
} else {
|
||||
return logUser(user, req.body.password, req, res, render);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
if (testPassword(req.body.password, user.password)) {
|
||||
req.session.user = user;
|
||||
|
||||
let redirection = req.session.redirectAfterLog || 'index';
|
||||
req.session.redirectAfterLog = undefined;
|
||||
req.session.save();
|
||||
|
||||
res.redirect(getUrl(redirection));
|
||||
} else {
|
||||
req.session.loginFailed = true;
|
||||
req.session.save();
|
||||
res.redirect(getUrl('login'));
|
||||
}
|
||||
return logUser(user, req.body.password, req, res, render);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue