我有关于闪信的问题。我没有在我的页面上收到错误消息。请告诉我错误在哪里。
PS。对不起我的英语;D
应用程序.js
要求:快递、护照、哈巴狗、快递会话、cookie-parser、connect-flash、body-parser...
var router = require('./router.js')(passport);
var initPassport = require('./passport-init.js');
var app = express();
app.set('views', __dirname + '/views');
app.set('view engine', 'pug');
app.use(cookieParser('secret'));
app.use(session({ cookie: { maxAge: 60000 }, secret: 'secret' }));
app.use(flash());
app.use(bodyParser.urlencoded({ extended: false }));
app.use(passport.initialize());
app.use('/', router);
initPassport(passport);
路由器.js
var express = require('express');
var router = express.Router();
module.exports = function(passport) {
router.get('/', function(req, res) {
res.render('index', {
title: 'index page'
});
});
router.post('/auth',
passport.authenticate('local', {
successRedirect: '/',
failureRedirect: '/',
failureFlash: true
})
);
return (router);
};
护照-init.js
var User = require('./user.js');
var LocalStrategy = require('passport-local').Strategy;
module.exports = function(passport) {
passport.use('local', new LocalStrategy({ usernameField: 'email', passwordField: 'pass', passReqToCallback: true },
function(email, pass, done) {
User.findOne({ where: { email: email } }).then(function(err, user) {
if (err) {
return done(err);
}
if (!user) { return done(null, false, { message: 'Incorrect username.' });
}
if (!user.validPassword(pass)) { return done(null, false, { message: 'Incorrect password.' });
}
return done(null, user);
});
}
));
};
和index.pug
include ./headers.pug
div(class="container")
div(class="row head")
div(class="col-xs-12")
if message
p #{message}
div(class="row body-left")
div(class="col-xs-3")
include ./auth.pug
div(class="col-xs-9")