无法在MEAN堆栈中传递更多参数
Cannot pass more parameters in MEAN Stack
你好,所以我的passport.js中有以下代码:
passport.use('local-signup', new LocalStrategy({
// by default, local strategy uses username and password, we will override with email
usernameField : 'email',
passwordField : 'password',
nameField: 'fullname',
passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, done, fullname) {
// 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.email' : email }, 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 email 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.email = email;
newUser.local.password = password;
newUser.local.fullname = fullname;
newUser.local.role = "default";
// save the user
newUser.save(function(err) {
if (err) {
throw err;
}
console.log(newUser);
return done(null, newUser);
});
}
});
});
}));
我需要将全名保存到数据库中,但不幸的是没有添加,因为这是完成后的最后一个参数。但是,如果在完成之前错误地放置全名,则不会找到返回的完成,并导致应用程序崩溃。
你认为什么是解决方案?
您可以从req
参数中检索全名。如果您使用的是bodyparser
,那么它和req.body.fullname
一样简单。在你需要的地方使用它。你需要确保你是用电子邮件和密码从表格中发送fullname
的。
passport的本地策略不支持除usernameField
和passwordField
之外的其他输入。如果您需要来自用户的其他输入,则需要从原始请求中检索这些输入。
相关文章:
- 函数参数中的数据与指定变量之间的任何性能差异
- 使用Express捕获参数
- 参数变量出现ngTable指令问题
- AngularJS:我可以跳过函数参数回调吗
- 如何使用skip参数使用angular ui引导进行服务器端分页
- 要求未定义JS回调参数
- 我的jQuery插件参数没有正确启动,遇到了问题
- 在自定义mean.io包中使用angular-chart.js作为依赖项
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- jquery设置为使用参数运行
- Javascript”;类“;带有参数的扩展
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 函数未将值作为参数传递
- 如何将参数传递到angularJs中的工厂
- 无法在MEAN堆栈中传递更多参数
- 从客户端控制器指定Mongo查询参数(MEAN.JS)
- 我如何传递参数到express.js服务器端路由为MEAN.js包
- 加载由MEAN堆栈中的URL参数(例如/users/:id)路由的视图
- Mean Stack——Angular将参数从控制器传递到$resource对象
- ''JavaScript函数参数中的mean