护照js'缺少证件'

时间:2018-05-06 06:32:14

标签: node.js

这是我的注册策略......

  passport.use('local-signup', new LocalStrategy({
      usernameField: 'email', 
      passwordField: 'password',
      passReqToCallback: true 
    }, function (req, email, password, done) {
          var e = req.body.email;
         var name= req.body.name;
         var phone = req.body.phone;
         var classc = req.body.classc;
         var graduated = req.body.graduated;
         var major = req.body.major;
         var minor = req.body.minor;
         var linkedin = req.body.linkedin;
         var bio = req.body.bio;

      log.console("TESTINGTESTING1");
      User.findOne({'email': email}, function (err, user) { 
        if (err)ß
        {
          log.console("TESTINGTESTING2");
         return done(null);
        }
        if (user) 
          {
            log.console("TESTINGTESTING3");
           return done(null, false, req.flash('signupMessage', 'existed email'));
          }
        log.console("TESTINGTESTING4");
        const newUser = new User();
        newUser.email = email; 
        newUser.password = newUser.generateHash(password); 
        newUser.name = name;
        newUser.phone = phone;
        newUser.classc = classc;
        newUser.graduated = graduated;
        newUser.major = major;
        newUser.minor = minor;
        newUser.linkedin = linkedin;
        newUser.bio = bio;

        log.console("TESTINGTESTING5");
        newUser.save(function (err) { 
          if (err)
          {
            log.console("TESTINGTESTING7");
           throw err;
          }
           log.console("TESTINGTESTING8");
          return done(null, newUser);
        });
      })
    }));

它总是发送failureRedirect所以我发现错误..

router.post('/register', function(req, res, next) {
    console.log(req.url);
    passport.authenticate('local-signin', function(err, user, info) {
        console.log("authenticate");
        console.log(err);
        console.log(user);
        console.log(info);
        console.log(req.body);
        res.send(JSON.stringify(info)).status(200)
    })(req, res, next);
});

这就是我得到的输出,它说Missing Credentials ...我该怎么做才能解决它?我已经将bodysarser东西放在我的中间件上,并且测试扩展了false和true ......但是我仍然得到了丢失的凭据。

app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: false }));

authenticate
null
false
{ message: 'Missing credentials' }
{ email: 'scott2008@google.com',
  password: [ 'abcde', 'abcde' ],
  name: 'adfa',
  phone: '3242523422',
  classc: '2014',
  graudated: 'on',
  major: 'African and African American Studies',
  minor: 'Biomedical Engineering',
  linkedin: 'adfas',
  bio: 'adfaf' }

0 个答案:

没有答案