Added email to password reset form automatically
parent
9cfbebb124
commit
7a99ed218a
|
@ -62,7 +62,7 @@ module.exports = (app, passport) => {
|
||||||
|
|
||||||
// Send token and alert user
|
// Send token and alert user
|
||||||
function sendToken(user){
|
function sendToken(user){
|
||||||
debug('sendToken(user)');
|
debug(`sendToken() called for user ${user.id}`);
|
||||||
|
|
||||||
// Create a password token
|
// Create a password token
|
||||||
user.createPassToken( (err,token,expires)=>{
|
user.createPassToken( (err,token,expires)=>{
|
||||||
|
@ -111,7 +111,7 @@ module.exports = (app, passport) => {
|
||||||
|
|
||||||
// User already exists
|
// User already exists
|
||||||
if (user && user.auth.password) {
|
if (user && user.auth.password) {
|
||||||
req.flash('warning','A user with that email already exists! If you forgot your password, you can <a href="/login/forgot">reset it here</a>.');
|
req.flash('warning',`A user with that email already exists! If you forgot your password, you can <a href="/login/forgot?email=${req.body.email}">reset it here</a>.`);
|
||||||
res.redirect('/login#login');
|
res.redirect('/login#login');
|
||||||
next();
|
next();
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ module.exports = (app, passport) => {
|
||||||
});
|
});
|
||||||
|
|
||||||
})(user.slug, (newSlug)=>{
|
})(user.slug, (newSlug)=>{
|
||||||
debug('Successfully created slug');
|
debug(`Successfully created slug: ${newSlug}`);
|
||||||
user.slug = newSlug;
|
user.slug = newSlug;
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
@ -179,7 +179,7 @@ module.exports = (app, passport) => {
|
||||||
}
|
}
|
||||||
if (buf) {
|
if (buf) {
|
||||||
user.sk32 = buf.toString('hex');
|
user.sk32 = buf.toString('hex');
|
||||||
debug('Successfully created sk32');
|
debug(`Successfully created sk32: ${user.sk32}`);
|
||||||
resolve();
|
resolve();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -187,7 +187,6 @@ module.exports = (app, passport) => {
|
||||||
|
|
||||||
// Save user and send the token by email
|
// Save user and send the token by email
|
||||||
Promise.all([slug, sk32])
|
Promise.all([slug, sk32])
|
||||||
// .then( ()=>{ user.save(); })
|
|
||||||
.then( ()=>{ sendToken(user); })
|
.then( ()=>{ sendToken(user); })
|
||||||
.catch( (err)=>{
|
.catch( (err)=>{
|
||||||
debug('Failed to save user after creating slug and sk32!');
|
debug('Failed to save user after creating slug and sk32!');
|
||||||
|
@ -208,13 +207,19 @@ module.exports = (app, passport) => {
|
||||||
|
|
||||||
// Forgot password
|
// Forgot password
|
||||||
app.route('/login/forgot')
|
app.route('/login/forgot')
|
||||||
|
|
||||||
|
// Check if user is already logged in
|
||||||
.all( (req,res,next)=>{
|
.all( (req,res,next)=>{
|
||||||
if (req.isAuthenticated()){ loginCallback(req,res); }
|
if (req.isAuthenticated()){ loginCallback(req,res); }
|
||||||
else { next(); }
|
else { next(); }
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
// Show forgot password page
|
||||||
.get( (req,res,next)=>{
|
.get( (req,res,next)=>{
|
||||||
res.render('forgot');
|
res.render('forgot', {email:req.query.email});
|
||||||
} )
|
} )
|
||||||
|
|
||||||
|
// Submitted forgot password form
|
||||||
.post( (req,res,next)=>{
|
.post( (req,res,next)=>{
|
||||||
|
|
||||||
// Validate email
|
// Validate email
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
<div class='form-group'>
|
<div class='form-group'>
|
||||||
<label for="email">Email:</label>
|
<label for="email">Email:</label>
|
||||||
<input name="email" type="email">
|
<input name="email" type="email" value="{{email}}">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<input class='main btn' type="submit" value="Go" style="display:block; margin:auto">
|
<input class='main btn' type="submit" value="Go" style="display:block; margin:auto">
|
||||||
|
|
Loading…
Reference in New Issue