我想在使用护照进行身份验证时显示错误或多条消息,我在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'
});
}
});
}
));
}