The first step
Of course, the preparation of work, in the bootstrap official website Download Good things, how to use the official website has been written in detail, in this is not detailed.
: http://v3.bootcss.com/getting-started/
Step Two
is to log in and register.
Written in the router file
Index.js
/*ucenter-Login */router.post ('/ucenter/login ', function (req, res) { user.findone ({name: req.body.name}, function (err, data) { if (data.name === req.body.name && Data.password === req.body.password) { console.log (req.body.name + ' Landing Success ' + new date ()); res.render (' Ucenter ', {title: ' Ucenter '}); } else { console.log (ERR); res.send (+); } });
/*ucenter-registered */router.post ('/ucenter/register ', function (req, res) { user.findone ({name: req.body.name}, function (Err, docs) { if (ERR) console.log (Err); else if (!docs) { user.create ({ name: req.body.name, password: req.body.password }, function (Err, doc) { if (ERR) Console.log (ERR); else console.log (DOC); }); res.render (' Ucenter ', { title: ' Ucenter '}); } });
The form submitted on the page with the action, not with Ajax, here for the convenience of explanation, if you write with the Ajax request writing
See: The Express Course in Http://www.hubwiz.com/coursecenter
There is a detailed approach.
Step Three
That's the problem with the express session.
Prior to express 4.0, middleware like session was automatically installed with Express,
Some tutorials on the web use the Express version just before 4.0, so be sure to note this when using the 4.0 and later versions.
This is required to implement the MongoDB callback to build Connect-mongo.
with express4:var session = require (' express-session ');var Mongostore = require (' Connect-mongo ') (session), App.use (session ({ secret: settings.cookie_secret, store: new mongostore ({ db : settings.db, }) }); With express<4:var express = require (' Express '); Var mongostore = require (' Connect-mongo ') (express); App.use (Express.session ({ secret: settings.cookie_secret, store: new mongostore ({ db: settings.db }) }); With connect:var connect = require (' Connect '); Var mongostore = require (' Connect-mongo ') (connect);
This code can then be seen in Connect-mongo GitHub.
The code hasn't been collated yet, and it's not uploaded to GitHub, so keep an eye on my blog.
All right, it's over.
node. js + MongoDB To do the Project (ii)