Mittwoch, 18. Mai, 2016
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
MongoDB CRUD the MVC way with Passport Authentication 77<br />
18 }));<br />
19<br />
20 app.get('/logout', users.logout);<br />
In the index.server.controller.js file add:<br />
1 exports.render = function(req, res) {<br />
2 res.render('index', {<br />
3 title: 'MEAN MVC',<br />
4 user: req.user ? req.user.username : ''<br />
5 });<br />
6 };<br />
In index.ejs file add:<br />
1 <br />
2 Hello <br />
3 Logout<br />
4 <br />
5 Register<br />
6 Login<br />
7 <br />
If you run this with node server now, you will get the error ‘Error: req.flash() requires sessions’.<br />
Well, you can fix this quickly by installing the sessions¹³³ module:<br />
1 $ npm install express-session --save<br />
and require it in the express.js file and add the use statement:<br />
1 var session = require('express-session');<br />
2<br />
3 app.use(session({<br />
4 saveUninitialized: true,<br />
5 resave: true,<br />
6 secret: 'OurSuperSecretCookieSecret'<br />
7 }));<br />
¹³³https://github.com/expressjs/session