我的模型的字段没有设置MEAN堆栈

时间:2016-09-09 22:20:33

标签: javascript passport.js mean-stack

在这里,您可以看到我的API控制器方法:



//need to export the api methods.
var mongoose = require('mongoose');
var User = require('../models/user');
var crypto = require('crypto');

module.exports.create = function(req, res) {

  //TODO: error checking.
  var user = new User();
  user.firstName = req.body.firstName;
  user.lastName = req.body.secondName;
  user.email = req.body.email;
  user.salt = crypto.randomBytes(16).toString('hex');
  user.password = crypto.pbkdf2Sync(req.body.password, user.salt, 1000, 64).toString('hex');
  //console.log(user);
  user.save(function(err) {
    res.status(200);
  });
};




这是我的模特:



var mongoose = require('mongoose');
var crypto = require('crypto');

module.exports = mongoose.model('User', {
  email: {
    type: String,
    unique: true,
    required: true
  },
  firstName: {
    type: String,
    required: true
  },
  lastName: {
    type: String,
    required: true
  },
  hash: String,
  salt: String
});




奇怪的是,即使我的req.body包含我试图设置的所有信息,当我在最后记录用户时,似乎唯一可以设置的东西是名字和盐?

有谁知道这是为什么?你能告诉我正确的方法吗?

由于

0 个答案:

没有答案