如何在视图中使用护照显示错误消息

时间:2014-06-23 13:11:26

标签: node.js

我想在使用护照进行身份验证时显示错误或多条消息,我在passport.js中的代码是:

var passport = require('passport');
var flash = require('connect-flash');
var LocalStrategy = require('passport-local').Strategy,
    User = require(process.cwd() + '/app/models/user');
module.exports = function() {
    passport.use(new LocalStrategy({
            usernamelocal: 'userid',
            passwordlocal: 'password'
        },
        function(username, password, done) {
            User.findOne({
                userid: username
            }, function(err, user) {

                if (err)
                    return done(err);

                if (!user) {
                    console.log("*************user name error");
                    this.message = "user error";

                    return done(null, false, {
                        message: 'unknown user'
                    });
                }
                if (user.deleted) {
                    console.log("user deleted error");
                    return done(null, false, {
                        message: 'unknown user'
                    });
                }
            });
        }
    ));
}

0 个答案:

没有答案