Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*==== /FORGOT-PASSWORD/CONFIRMATION ====*/
- siteRoutes.route('/password-reset/type/:response')
- .get(function(req, res){
- var resetRequest;
- var resetConfirmation;
- if (req.params.response = "request"){
- resetRequest = true;
- console.log("Request Param");
- console.log("Request is set to " + resetRequest);
- } else if (req.params.response = "confirmation"){
- resetConfirmation = true;
- console.log("Confirmation Param");
- console.log("Confirmation is set to " + resetConfirmation);
- } else {
- return null;
- console.log("Null");
- }
- res.render('pages/site/password-reset-confirmation.hbs', {
- message: req.flash('info'),
- resetRequest: resetRequest,
- resetConfirmation: resetConfirmation
- });
- });
- /*==== /FORGOT-PASSWORD ====*/
- siteRoutes.route('/password-reset')
- .get(function(req, res){
- res.render('pages/site/forgot-password.hbs');
- })
- .post(function(req, res){
- req.flash('info', 'Please check your email for the reset link.');
- res.redirect('/password-reset/type/request');
- })], function(error){
- if(error){
- console.log(error);
- }
- })
- });
- /*==== /RESET ====*/
- siteRoutes.route('/password-reset/:token')
- .get(function(req, res){
- var urlPath = url.parse(req.url).pathname.split('/');
- var urlToken = urlPath[2];
- console.log(urlToken);
- models.User.findOne({
- where: {
- resetPasswordToken: req.params.token,
- resetPasswordExpires: {
- $gt: moment().format('YYYY-MM-DD HH:mm:ss')
- }
- }
- }).then(function(user){
- res.render('pages/app/password-reset.hbs',{
- urlToken: urlToken,
- user: user
- });
- })
- })
- .post(function(req, res){
- async.waterfall([
- function(done){
- models.User.update({
- password: models.User.generateHash(req.body.password),
- resetPasswordToken: null,
- resetPasswordExpires: null
- }, { where: {
- resetPasswordToken: req.body.token,
- resetPasswordExpires: {
- $gt: moment().format('YYYY-MM-DD HH:mm:ss')
- }
- }})
- // Nodemailer
- var transporter = nodemailer.createTransport(sgTransport(options));
- var mailOptions = {
- from: '"Test@test.com',
- to: req.body.email,
- subject: 'Your Password has Been Changed',
- text: 'Hello,nn' +
- 'This is a confirmation that the password for the email associated with your Test account, ' + req.body.email + ' has just been changed. If there has been a mistake or you did not change the password, then please contact us as soon as possible at support@test.comn'
- };
- transporter.sendMail(mailOptions, function(error, info){
- if(error){
- return console.log(error + 'During Post');
- }
- console.log('Message sent: ' + info);
- })
- }
- ])
- req.flash('info', 'You have successfully updated your password.');
- res.redirect('/password-reset/type/confirmation');
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement