Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/node.js/39.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Node.js 邮寄枪验证电子邮件后护照不起作用_Node.js_Validation_Email_Mailgun_Passport.js - Fatal编程技术网

Node.js 邮寄枪验证电子邮件后护照不起作用

Node.js 邮寄枪验证电子邮件后护照不起作用,node.js,validation,email,mailgun,passport.js,Node.js,Validation,Email,Mailgun,Passport.js,我正在使用并尝试验证电子邮件,然后根据该电子邮件创建用户帐户。我可以让它验证电子邮件,但它不会完成实际创建用户的POST请求。它最终会显示一个日志,但它甚至没有给出一个我觉得奇怪的状态码。我经常看到这个。通常是这样,但这一次只是状态代码所在的位置 Passport.use注册中间件 passport.use('signup', new LocalStrategy({ usernameField: 'email', passReqToCallback : true

我正在使用并尝试验证电子邮件,然后根据该电子邮件创建用户帐户。我可以让它验证电子邮件,但它不会完成实际创建用户的
POST
请求。它最终会显示一个日志,但它甚至没有给出一个我觉得奇怪的状态码。我经常看到这个。通常是这样,但这一次只是状态代码所在的位置

Passport.use注册中间件

passport.use('signup', new LocalStrategy({
      usernameField: 'email',
      passReqToCallback : true
    },
    function(req, email, password, done) {
      var findOrCreateUser = function(){
        console.log(req.body.email);
        User.findOne({ email: req.body.email }, function(err, existingUser) {
          if(err){
            console.log(err);
          }
          if (existingUser) {
            req.flash('form', {
              email: req.body.email
            });
            return done(null, false, req.flash('error', 'An account with that email address already exists.'));
          }
          // edit this portion to accept other properties when creating a user.
          var user = new User({
            email: req.body.email,
            password: req.body.password // user schema pre save task hashes this password
          });

          user.save(function(err) {
            if (err) return done(err, false, req.flash('error', 'Error saving user.'));

            var token = new Token({ _userId: user._id, token: crypto.randomBytes(16).toString('hex') });
            token.save(function (err) {
            if (err) return done(null, false, req.flash('error', err.message));
            var email = req.body.email;
            // Send the email
            var message = 'Hello,\n\n' + 'Please verify your account by clicking the link: \nhttp:\/\/' + req.headers.host + '\/confirmation\/' + token.token + '\/' + email + '\n';
            sendEmail('"Phantom Asset Management" noreply@phantomam.com', user.email, 'Account Verification Token', message);
            });
            var time = 14 * 24 * 3600000;
            req.session.cookie.maxAge = time; //2 weeks
            req.session.cookie.expires = new Date(Date.now() + time);
            req.session.touch();
            return done(null, user, req.flash('success', 'A verification email has been sent to ' + user.email + '.'));
          });
          console.log('done');
        });
      };

      process.nextTick(findOrCreateUser);

    })
  );
然后是我的控制器

exports.postSignup = function(req, res, next){
  req.assert('email', 'Please sign up with a valid email.').isEmail();
  req.assert('password', 'Password must be at least 6 characters long').len(6);

  var errors = req.validationErrors();

  if (errors) {
    req.flash('errors', errors);
    req.flash('form', {
      email: req.body.email
    });
    return res.redirect('/signup');
  }
  validator(req.body.email, function (err, result){
  if(err) {
    return console.log('Error: ', err); 
  } else {
    console.log('Result: ', result);
    if(result.is_valid == false){
      req.flash('error', 'Looks like your email is not valid did you mean ' + result.did_you_mean + '?');
        return res.redirect(req.redirect.failure);
    } else if(result.is_valid == true) {
      // calls next middleware to authenticate with passport
      passport.authenticate('signup', {
        successRedirect: '/dashboard', // Select redirect for post signup
        failureRedirect: '/signup',
        failureFlash : true
      });
    }
  }
});
  (req, res, next);
    next();
};
如果我对如何使用密码的理解是正确的,它首先会检查以确保它是电子邮件,然后密码的长度是正确的。如果有错误,它会让用户知道并将其重定向回
/signup
。然后它进入验证器,或者向控制台提供一个错误,或者检查它是否有效。如果无效,则向用户显示一个错误,但如果有效,则进入我的passport中间件

这应该采取并检查用户是否存在,然后标志错误是必要的。它保存用户和令牌,供该用户用于验证其电子邮件地址。除了保存用户和令牌之外,这一切都很好

看起来这可能是一个
request.js
问题,我得到了
错误:esocketimedout
mailgun-validate-email
的唯一依赖项就是
request 2.25.0
esockettimedout
request.js:813:19