我在这里练习nodejs mongoose passport教程:http://www.scotchmedia.com/tutorials/express/authentication/2/03。这是一个由多个部分组成的教程,我已经被困在其中一个步骤中三天了。我怀疑代码中有一个遗漏的语句,但不是很确定,我无法与作者联系。
我用一串问号在行中注释它,?你能看一下吗。提前谢谢。
var emailSchema = new Schema({
// Since `type` is special keyword in mongoose we must set the def. to
// and object. I.e. this would not work:
// type: String,
type : {type: String},
value : String
});
// define the userSchema
var userSchema = new Schema({
name : {
givenName : String,
familyName : String
},
emails: [emailSchema],
passwordHash: String
});
exports.signup = function (req, res) {
req.onValidationError(function (msg) {
//Redirect to `/signup` if validation fails
return res.redirect('/signup');
});
req.check('email', 'Please enter a valid email').len(1).isEmail();
req.check('password', 'Please enter a password with a length between 4 and 34 digits').len(4, 34);
req.check('givenName', 'Please enter your first name').len(1);
req.check('familyName', 'Please enter your last name').len(1);
// If the form is valid craete a new user
var newUser = {
name: {
givenName: req.body.givenName,
familyName: req.body.familyName
},
emails: [
{
value: req.body.email
}
]
// Is something (like passwordHash) missing here ??????????????
};
// hash password
User.hashPassword(req.body.password, function (err, passwordHash) {
// update attributes
newUser.passwordHash = passwordHash;
// Create new user
User.create(newUser, function (err, user) {
return res.redirect('/account');
});
});
};发布于 2014-05-08 15:05:43
看一下:
newUser.passwordHash = passwordHash;密码哈希已设置。
所以这里没有遗漏任何东西
https://stackoverflow.com/questions/23531252
复制相似问题