nodejs-passport:done不是一个函数

时间:2017-01-03 10:11:13

标签: node.js passport.js

我有“完成不是功能”错误。我试图删除passReqToCallback参数,但它仍然无法正常工作。我不确定为什么请帮忙。

它就行了:return done(null,false,req.flash('signupMessage','那个用户名已经被占用。'));

// =========================================================================
// 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
    emailField : 'email',
    usernameField : 'username',
    passwordField : 'password',
    passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, username, password, done) {

    // 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.find({ 'local.email' :  email, '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 found.
        if (user.length!=0) {
            if(user[0].username){
                return done(null, false, req.flash('signupMessage', 'That username is already taken.'));                         
            }else{
                return done(null, false, req.flash('signupMessage', 'That email is already taken.'));     
            }                                    
            return done(err);
        }
        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.username = username;
            newUser.local.password = newUser.generateHash(password);

            // save the user
            newUser.save(function(err) {
                if (err)
                    throw err;
                return done(null, true);
            });
        }

    });    

    });

}));

    // =========================================================================
// LOCAL LOGIN =============================================================
// =========================================================================
// 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-login', new LocalStrategy({
    // by default, local strategy uses username and password, we will override with email
    usernameField : 'userIdentityField',
    passwordField : 'password',
    passReqToCallback : true // allows us to pass back the entire request to the callback
},
function(req, email, password, done) { // callback with email and password from our form

    // 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.isValidUserPassword(email, password, done);

}));

};

0 个答案:

没有答案