From 08d4d6b5bf8f18366696c9bba603e20cc9b602a9 Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 14 Oct 2014 11:42:10 -0400 Subject: [PATCH 1/2] changed indentation for continueLogin method in authentication.js --- src/routes/authentication.js | 74 ++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 37 deletions(-) diff --git a/src/routes/authentication.js b/src/routes/authentication.js index 2378bec052..c405649f66 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -34,50 +34,50 @@ function login(req, res, next) { var continueLogin = function() { - passport.authenticate('local', function(err, userData, info) { - if (err) { - req.flash('error', info); - return res.redirect(nconf.get('relative_path') + '/login'); - } - - if (!userData) { - if (typeof info === 'object') { - info = '[[error:invalid-username-or-password]]'; + passport.authenticate('local', function(err, userData, info) { + if (err) { + req.flash('error', info); + return res.redirect(nconf.get('relative_path') + '/login'); } - req.flash('error', info); - return res.redirect(nconf.get('relative_path') + '/login'); - } - - // Alter user cookie depending on passed-in option - if (req.body.remember === 'on') { - var duration = 1000*60*60*24*parseInt(meta.config.loginDays || 14, 10); - req.session.cookie.maxAge = duration; - req.session.cookie.expires = new Date(Date.now() + duration); - } else { - req.session.cookie.maxAge = false; - req.session.cookie.expires = false; - } - - req.login({ - uid: userData.uid - }, function() { - if (userData.uid) { - user.logIP(userData.uid, req.ip); + if (!userData) { + if (typeof info === 'object') { + info = '[[error:invalid-username-or-password]]'; + } - plugins.fireHook('action:user.loggedIn', userData.uid); + req.flash('error', info); + return res.redirect(nconf.get('relative_path') + '/login'); } - if (!req.session.returnTo) { - res.redirect(nconf.get('relative_path') + '/'); + // Alter user cookie depending on passed-in option + if (req.body.remember === 'on') { + var duration = 1000*60*60*24*parseInt(meta.config.loginDays || 14, 10); + req.session.cookie.maxAge = duration; + req.session.cookie.expires = new Date(Date.now() + duration); } else { - var next = req.session.returnTo; - delete req.session.returnTo; - res.redirect(nconf.get('relative_path') + next); + req.session.cookie.maxAge = false; + req.session.cookie.expires = false; } - }); - })(req, res, next); - }; + + req.login({ + uid: userData.uid + }, function() { + if (userData.uid) { + user.logIP(userData.uid, req.ip); + + plugins.fireHook('action:user.loggedIn', userData.uid); + } + + if (!req.session.returnTo) { + res.redirect(nconf.get('relative_path') + '/'); + } else { + var next = req.session.returnTo; + delete req.session.returnTo; + res.redirect(nconf.get('relative_path') + next); + } + }); + })(req, res, next); + }; if(meta.config.allowLocalLogin !== undefined && parseInt(meta.config.allowLocalLogin, 10) === 0) { return res.status(404).send(''); From b5481ceed20ba0dea65e44426f912503751aec1a Mon Sep 17 00:00:00 2001 From: Julian Lam Date: Tue, 14 Oct 2014 11:48:16 -0400 Subject: [PATCH 2/2] property fixed #2087 --- public/src/client/login.js | 10 ++++++++++ src/routes/authentication.js | 5 +++++ 2 files changed, 15 insertions(+) diff --git a/public/src/client/login.js b/public/src/client/login.js index c4600c36ac..e7079ddfed 100644 --- a/public/src/client/login.js +++ b/public/src/client/login.js @@ -33,6 +33,16 @@ define('forum/login', function() { }); $('#content #username').focus(); + + // Add "returnTo" data if present + if (app.previousUrl) { + var returnToEl = document.createElement('input'); + returnToEl.type = 'hidden'; + returnToEl.name = 'returnTo'; + returnToEl.value = app.previousUrl.replace(window.location.origin + RELATIVE_PATH, ''); + $(returnToEl).appendTo(formEl); + console.log('appended'); + } }; return Login; diff --git a/src/routes/authentication.js b/src/routes/authentication.js index c405649f66..edd984bc4b 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -83,6 +83,11 @@ return res.status(404).send(''); } + // Handle returnTo data + if (req.body.hasOwnProperty('returnTo') && !req.session.returnTo) { + req.session.returnTo = req.body.returnTo; + } + if (req.body.username && utils.isEmailValid(req.body.username)) { user.getUsernameByEmail(req.body.username, function(err, username) { if (err) {