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.
|
| Username or password incorrect. Please try again.
|
||||||
form(method="POST", action=getUrl("loginTarget"))
|
form(method="POST", action=getUrl("loginTarget"))
|
||||||
.form-group
|
.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
|
.form-group
|
||||||
input.form-control(type="password", name="password", placeholder="Password")
|
input.form-control(type="password", name="password", placeholder="Password")
|
||||||
.form-group
|
.form-group
|
||||||
|
|
|
@ -48,12 +48,8 @@ module.exports.logout = function(req, res, render) {
|
||||||
res.redirect(getUrl("index"));
|
res.redirect(getUrl("index"));
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.loginTarget = function(req, res, render) {
|
function logUser(user, password, req, res, render) {
|
||||||
User.getByUsername(req.body.username, (err, user) => {
|
if (testPassword(password, user.password)) {
|
||||||
if (user === undefined || !user.active) {
|
|
||||||
res.redirect(getUrl('login'));
|
|
||||||
} else {
|
|
||||||
if (testPassword(req.body.password, user.password)) {
|
|
||||||
req.session.user = user;
|
req.session.user = user;
|
||||||
|
|
||||||
let redirection = req.session.redirectAfterLog || 'index';
|
let redirection = req.session.redirectAfterLog || 'index';
|
||||||
|
@ -66,6 +62,22 @@ module.exports.loginTarget = function(req, res, render) {
|
||||||
req.session.save();
|
req.session.save();
|
||||||
res.redirect(getUrl('login'));
|
res.redirect(getUrl('login'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports.loginTarget = function(req, res, render) {
|
||||||
|
User.getByUsername(req.body.username, (err, user) => {
|
||||||
|
if (user === undefined || !user.active) {
|
||||||
|
// 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 {
|
||||||
|
return logUser(user, req.body.password, req, res, render);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue