From 4628b06fd60e9bef7162cb1051ae5ee5f4bc109d Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Tue, 16 Jun 2015 11:38:48 +0530 Subject: [PATCH] FIX: use session instead of cookie to preserve url --- app/assets/javascripts/discourse/controllers/login.js.es6 | 7 +++++-- app/assets/javascripts/discourse/routes/new-topic.js.es6 | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index 6ede862f1d2..7db0f9b3aae 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -76,13 +76,16 @@ export default DiscourseController.extend(ModalFunctionality, { // Trigger the browser's password manager using the hidden static login form: var $hidden_login_form = $('#hidden-login-form'); var destinationUrl = $.cookie('destination_url'); + var shouldRedirectToUrl = self.session.get("shouldRedirectToUrl"); $hidden_login_form.find('input[name=username]').val(self.get('loginName')); $hidden_login_form.find('input[name=password]').val(self.get('loginPassword')); - if ((self.get('loginRequired') || $.cookie('shouldRedirectToUrl')) && destinationUrl) { + if (self.get('loginRequired') && destinationUrl) { // redirect client to the original URL $.cookie('destination_url', null); - $.cookie('shouldRedirectToUrl', null); $hidden_login_form.find('input[name=redirect]').val(destinationUrl); + } else if (shouldRedirectToUrl) { + self.session.set("shouldRedirectToUrl", null); + $hidden_login_form.find('input[name=redirect]').val(shouldRedirectToUrl); } else { $hidden_login_form.find('input[name=redirect]').val(window.location.href); } diff --git a/app/assets/javascripts/discourse/routes/new-topic.js.es6 b/app/assets/javascripts/discourse/routes/new-topic.js.es6 index 9c26ce5c8cc..d27d6a2363c 100644 --- a/app/assets/javascripts/discourse/routes/new-topic.js.es6 +++ b/app/assets/javascripts/discourse/routes/new-topic.js.es6 @@ -13,7 +13,7 @@ export default Discourse.Route.extend({ }); } else { // User is not logged in - $.cookie('shouldRedirectToUrl', true); + self.session.set("shouldRedirectToUrl", window.location.href); self.replaceWith('login'); } }