护照策略挂起且未重置密码

时间:2018-08-31 14:50:46

标签: node.js express passport.js forgot-password

我有一条路由,该路由仅调用一个函数,该函数应该向用户发送包含链接的电子邮件,并且该链接应包含令牌。带有链接和令牌的电子邮件将发送给用户。令牌已保存在用户的个人资料中,并且应该保存在tokens集合中,但没有保存在那里。

第二部分是路由一直挂起,直到超时到云9上的错误502。

除了超时,我没有给出任何堆栈跟踪或错误消息。我得到了一个空白的morgan(npm的软件包)语句,但缺少时间。

关于出什么问题的任何想法?

路线

// POST FORGOT
app.post('/user/forgot', 
users.postForgotPassword);

用户发布的忘记密码功能

exports.postForgotPassword = (req, res, next) => {
  req.assert('email', 'Please enter a valid email address.').isEmail();

  var errors = req.validationErrors();

  if (errors) {
    req.flash('form', {
      email: req.body.email
    });
    req.flash('errors', errors);
    console.log(errors);
    return res.redirect('/');
  }

  async.waterfall([
    function(done) {
      crypto.randomBytes(16, function(err, buf) {
        var token = buf.toString('hex');
        done(err, token);
      });
    },
    function(token, done) {
      User.findOne({ email: req.body.email.toLowerCase() }, function(err, user) {
      if(err){
        console.log(err);
      }
        if (!user) {
          req.flash('form', {
            email: req.body.email
          });
          req.flash('error', 'No account with that email address exists.');
          return res.redirect('/forgot');
        }

        user.resetPasswordToken = token;
        user.resetPasswordExpires = Date.now() + 3600000; // 1 hour

        user.save(function(err) {
          done(err, token, user);
        });
      });
    },
    function(token, user, done) {

      var newUserEmail = req.body.email;
      var message= 'You are receiving this email because you (or someone else) have requested the reset of the password for your account.\n\n' +
          'Please click on the following link, or paste this into your browser to complete the process:\n\n' +
          'http://' + req.headers.host + '/reset/' + token + '\n\n' +
          'If you did not request this, please ignore this email and your password will remain unchanged.\n';
      sendEmail('noreply@domain.com', newUserEmail, 'Reset your password on <site name>', message);
    }
  ], function(err) {
    if (err) return next(err);
    res.redirect('/login');
  });
};

0 个答案:

没有答案
相关问题