Nice error messages
This commit is contained in:
parent
e8f827e6a7
commit
f134b08ecf
|
@ -4,6 +4,9 @@ block content
|
||||||
.row
|
.row
|
||||||
.col
|
.col
|
||||||
.col
|
.col
|
||||||
|
if passwordForgottenFailed
|
||||||
|
.alert.alert-danger
|
||||||
|
| This email does not exist in our database.
|
||||||
form(method="POST", action=getUrl("passwordForgottenTarget"))
|
form(method="POST", action=getUrl("passwordForgottenTarget"))
|
||||||
.form-group
|
.form-group
|
||||||
input.form-control(type="text", name="email", placeholder="Enter your email address", autofocus)
|
input.form-control(type="text", name="email", placeholder="Enter your email address", autofocus)
|
||||||
|
|
|
@ -149,13 +149,20 @@ module.exports.activate = function(req, res, render, next) {
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.passwordForgotten = function(req, res, render, next) {
|
module.exports.passwordForgotten = function(req, res, render, next) {
|
||||||
|
if (req.session.passwordForgottenFailed) {
|
||||||
|
res.locals.passwordForgottenFailed = req.session.passwordForgottenFailed;
|
||||||
|
req.session.passwordForgottenFailed = undefined;
|
||||||
|
req.session.save();
|
||||||
|
}
|
||||||
render('passwordForgotten.pug');
|
render('passwordForgotten.pug');
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.passwordForgottenTarget = function(req, res, render, next) {
|
module.exports.passwordForgottenTarget = function(req, res, render, next) {
|
||||||
User.getByEmail(req.body.email, (err, user) => {
|
User.getByEmail(req.body.email, (err, user) => {
|
||||||
if (err !== undefined) {
|
if (err !== undefined) {
|
||||||
return res.send("Nope");
|
req.session.passwordForgottenFailed = true;
|
||||||
|
req.session.save();
|
||||||
|
return res.redirect(getUrl('passwordForgotten'));
|
||||||
}
|
}
|
||||||
|
|
||||||
require('crypto').randomBytes(48, function(err, buffer) {
|
require('crypto').randomBytes(48, function(err, buffer) {
|
||||||
|
@ -163,7 +170,9 @@ module.exports.passwordForgottenTarget = function(req, res, render, next) {
|
||||||
user.save();
|
user.save();
|
||||||
|
|
||||||
if (!user.active) {
|
if (!user.active) {
|
||||||
return res.send("Nope");
|
req.session.passwordForgottenFailed = true;
|
||||||
|
req.session.save();
|
||||||
|
return res.redirect(getUrl('passwordForgotten'));
|
||||||
}
|
}
|
||||||
|
|
||||||
res.locals.user = user;
|
res.locals.user = user;
|
||||||
|
|
Loading…
Reference in New Issue