护照本地猫鼬帐户注册的其他字段? [英] Additional fields to passport-local-mongoose account registration?

查看:70
本文介绍了护照本地猫鼬帐户注册的其他字段?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将passport-local-mongoose 与Node.js、Express.js、MongoDB 一起用于Web 应用程序,我想使用用户名字段、密码字段、公司名称字段和电话号码注册用户字段(全部为字符串).但是,我只能获取要在数据库中显示的用户名和加盐密码.我如何同时在数据库中包含公司名称和电话号码字段?

I'm using passport-local-mongoose with Node.js, Express.js, MongoDB for a webapp, and I want to register users with a username field, a password field, a company name field, and a phone number field (all as Strings). However I am only able to get the username and salted password to show in the database. How do I also include the company name and the phone number fields in the database?

推荐答案

只需传入所需的模型字段作为选项.

Just pass in the required model fields as an option.

var mongoose = require('mongoose'),
    passportLocalMongoose = require('passport-local-mongoose');

var userSchema = mongoose.Schema;
var User = new userSchema({
    username: ...,
    admin: ...,
    // Configure other schema fields
});

User.plugin(passportLocalMongoose, {
   selectFields : 'username admin etc' //Space seperate the required fields
);

注册时,

// user_details contains all information required
// for registration such as username, password, admin, etc.
User.register(new User(user_details), user_password, cb);

这篇关于护照本地猫鼬帐户注册的其他字段?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆