首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nodejs教程:用户注册

Nodejs教程:用户注册
EN

Stack Overflow用户
提问于 2014-05-08 09:34:30
回答 1查看 168关注 0票数 0

我在这里练习nodejs mongoose passport教程:http://www.scotchmedia.com/tutorials/express/authentication/2/03。这是一个由多个部分组成的教程,我已经被困在其中一个步骤中三天了。我怀疑代码中有一个遗漏的语句,但不是很确定,我无法与作者联系。

我用一串问号在行中注释它,?你能看一下吗。提前谢谢。

代码语言:javascript
复制
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');
        });
    });
};
EN

回答 1

Stack Overflow用户

发布于 2014-05-08 15:05:43

看一下:

代码语言:javascript
复制
newUser.passwordHash = passwordHash;

密码哈希已设置。

所以这里没有遗漏任何东西

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23531252

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档