Nice error messages

This commit is contained in:
Thomas Forgione 2017-09-29 14:42:42 +02:00
parent e8f827e6a7
commit f134b08ecf
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
2 changed files with 14 additions and 2 deletions

View File

@ -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)

View File

@ -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;