From 412358b0705f8ab1547488ad78f524621d3d7f41 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20Soner=20U=C5=9Fakl=C4=B1?= Date: Wed, 31 Oct 2018 19:12:33 -0400 Subject: [PATCH] #6903 --- src/controllers/index.js | 3 ++- src/routes/authentication.js | 17 +++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/src/controllers/index.js b/src/controllers/index.js index 89cfb2e06e..df2d9bdeb6 100644 --- a/src/controllers/index.js +++ b/src/controllers/index.js @@ -212,8 +212,9 @@ Controllers.registerInterstitial = function (req, res, next) { function (data, next) { if (!data.interstitials.length) { // No interstitials, redirect to home + const returnTo = req.session.returnTo || req.session.registration.returnTo; delete req.session.registration; - return res.redirect(nconf.get('relative_path') + '/'); + return res.redirect(returnTo || nconf.get('relative_path') + '/'); } var renders = data.interstitials.map(function (interstitial) { return async.apply(req.app.render.bind(req.app), interstitial.template, interstitial.data || {}); diff --git a/src/routes/authentication.js b/src/routes/authentication.js index a15c074806..e5173cd456 100644 --- a/src/routes/authentication.js +++ b/src/routes/authentication.js @@ -73,17 +73,14 @@ Auth.reloadRoutes = function (router, callback) { }, function (req, res, next) { // Trigger registration interstitial checks req.session.registration = req.session.registration || {}; + // save returnTo for later usage in /register/complete + // passport seems to remove `req.session.returnTo` after it redirects + req.session.registration.returnTo = req.session.returnTo; next(); - }, function (req, res, next) { - let successReturnToOrRedirect = nconf.get('relative_path') + (strategy.successUrl !== undefined ? strategy.successUrl : '/'); - if (req.session && req.session.returnTo) { - successReturnToOrRedirect = req.session.returnTo; - } - passport.authenticate(strategy.name, { - successReturnToOrRedirect: successReturnToOrRedirect, - failureRedirect: nconf.get('relative_path') + (strategy.failureUrl !== undefined ? strategy.failureUrl : '/login'), - })(req, res, next); - }); + }, passport.authenticate(strategy.name, { + successReturnToOrRedirect: nconf.get('relative_path') + (strategy.successUrl !== undefined ? strategy.successUrl : '/'), + failureRedirect: nconf.get('relative_path') + (strategy.failureUrl !== undefined ? strategy.failureUrl : '/login'), + })); }); router.post('/register', Auth.middleware.applyCSRF, Auth.middleware.applyBlacklist, controllers.authentication.register);