Tôi thấy rằng điều này hoạt động tốt hơn. Nó có vẻ là chìa khóa mà thực hiện được sau khi req, tên người dùng, mật khẩu, nhưng trước khi các biến khác mà bạn mong muốn để vượt qua vào chức năng. Nếu hoàn thành được đặt vào cuối thì:
events.js:160 throw er; // Unhandled 'error' event TypeError: done is not a function
sẽ được trả lại.
// =========================================================================
// LOCAL SIGNUP ============================================================
// =========================================================================
// we are using named strategies since we have one for login and one for signup
// by default, if there was no name, it would just be called 'local'
passport.use('local-signup', new LocalStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField : 'username',
passwordField : 'password',
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, username, password, done, fname, lname, email, security_question, security_answer) {
// asynchronous
// User.findOne wont fire unless data is sent back
process.nextTick(function() {
// find a user whose email is the same as the forms email
// we are checking to see if the user trying to login already exists
User.findOne({ 'local.username' : username }, function(err, user) {
// if there are any errors, return the error
if (err)
return done(err);
// check to see if theres already a user with that email
if (user) {
return done(null, false, req.flash('signupMessage', 'That username is already taken.'));
} else {
// if there is no user with that email
// create the user
var newUser = new User();
// set the user's local credentials
newUser.local.fname = fname;
newUser.local.lname = lname;
newUser.local.username = username;
newUser.local.email = email;
newUser.local.password = newUser.generateHash(password);
newUser.local.security_question = security_question;
newUser.local.security_answer = newUser.generateHash(security_answer);
// save the user
newUser.save(function(err) {
if (err)
throw err;
return done(null, newUser);
});
}
});
});
}));
Nguồn
2016-12-08 21:17:55
args req, tên người dùng và mật khẩu được thực hiện đều được ... nhưng làm cách nào chúng tôi có thể chuyển các thông số bổ sung như fname, lname, v.v ...? trước hết, thực sự từ đâu nó sẽ lấy tên người dùng và mật khẩu ..? từ req.body hoặc từ một số nơi khác ..? Cảm ơn trước.. – shivaraj