From 7a99ed218a794564156bf664cbce6e873fa2c543 Mon Sep 17 00:00:00 2001 From: Keith Irwin Date: Fri, 14 Jul 2017 03:24:58 -0400 Subject: [PATCH] Added email to password reset form automatically --- config/routes/auth.js | 17 +++++++++++------ views/forgot.html | 2 +- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/config/routes/auth.js b/config/routes/auth.js index 1f34892..819acf3 100644 --- a/config/routes/auth.js +++ b/config/routes/auth.js @@ -62,7 +62,7 @@ module.exports = (app, passport) => { // Send token and alert user function sendToken(user){ - debug('sendToken(user)'); + debug(`sendToken() called for user ${user.id}`); // Create a password token user.createPassToken( (err,token,expires)=>{ @@ -111,7 +111,7 @@ module.exports = (app, passport) => { // User already exists if (user && user.auth.password) { - req.flash('warning','A user with that email already exists! If you forgot your password, you can reset it here.'); + req.flash('warning',`A user with that email already exists! If you forgot your password, you can reset it here.`); res.redirect('/login#login'); next(); } @@ -162,7 +162,7 @@ module.exports = (app, passport) => { }); })(user.slug, (newSlug)=>{ - debug('Successfully created slug'); + debug(`Successfully created slug: ${newSlug}`); user.slug = newSlug; resolve(); }); @@ -179,7 +179,7 @@ module.exports = (app, passport) => { } if (buf) { user.sk32 = buf.toString('hex'); - debug('Successfully created sk32'); + debug(`Successfully created sk32: ${user.sk32}`); resolve(); } }); @@ -187,7 +187,6 @@ module.exports = (app, passport) => { // Save user and send the token by email Promise.all([slug, sk32]) - // .then( ()=>{ user.save(); }) .then( ()=>{ sendToken(user); }) .catch( (err)=>{ debug('Failed to save user after creating slug and sk32!'); @@ -208,13 +207,19 @@ module.exports = (app, passport) => { // Forgot password app.route('/login/forgot') + + // Check if user is already logged in .all( (req,res,next)=>{ if (req.isAuthenticated()){ loginCallback(req,res); } else { next(); } } ) + + // Show forgot password page .get( (req,res,next)=>{ - res.render('forgot'); + res.render('forgot', {email:req.query.email}); } ) + + // Submitted forgot password form .post( (req,res,next)=>{ // Validate email diff --git a/views/forgot.html b/views/forgot.html index 68f0426..3c3b0ea 100644 --- a/views/forgot.html +++ b/views/forgot.html @@ -16,7 +16,7 @@
- +