diff --git a/README.md b/README.md index e28e4df0e8..d7f90f662e 100644 --- a/README.md +++ b/README.md @@ -1009,10 +1009,6 @@ Add this to `package.json`, after *name* and *version*. This is necessary becaus - **Note:** *You will be prompted for the password you created earlier* - On **Deployments** tab of your Windows Azure Web Site, you will see the deployment history -TODO ----- -- Pages that require login, should automatically redirect to last attempted URL on successful sign-in. - Contributing ------------ If something is unclear, confusing, or needs to be refactored, please let me know. Pull requests are always welcome, but due to the opinionated nature of this project, I cannot accept every pull request. Please open an issue before submitting a pull request. This project uses [Airbnb JavaScript Style Guide](https://github.com/airbnb/javascript) with a few minor exceptions. If you are submitting a pull request that involves Jade templates, please make sure you are using *spaces*, not tabs. diff --git a/controllers/user.js b/controllers/user.js index 97bbb5ec30..0d6c53b816 100644 --- a/controllers/user.js +++ b/controllers/user.js @@ -9,6 +9,7 @@ var User = require('../models/User'); exports.getLogin = function(req, res) { if (req.user) return res.redirect('/'); + req.session.lastUrl = req.header('Referrer'); res.render('account/login', { title: 'Login' }); @@ -34,16 +35,14 @@ exports.postLogin = function(req, res, next) { passport.authenticate('local', function(err, user, info) { if (err) return next(err); - if (!user) { req.flash('errors', { msg: info.message }); return res.redirect('/login'); } - req.logIn(user, function(err) { if (err) return next(err); req.flash('success', { msg: 'Success! You are logged in.' }); - return res.redirect('/'); + res.redirect(req.session.lastUrl || '/'); }); })(req, res, next); };