From d1632c1dbd256411bbb348f638bb7f5f61f05eae Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Sun, 14 Jun 2015 20:24:47 +0530 Subject: [PATCH] FIX: new-topic URL should survive login redirection --- app/assets/javascripts/discourse/controllers/login.js.es6 | 3 ++- app/assets/javascripts/discourse/routes/new-topic.js.es6 | 1 + app/controllers/static_controller.rb | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/app/assets/javascripts/discourse/controllers/login.js.es6 b/app/assets/javascripts/discourse/controllers/login.js.es6 index ccb68864e..6ede862f1 100644 --- a/app/assets/javascripts/discourse/controllers/login.js.es6 +++ b/app/assets/javascripts/discourse/controllers/login.js.es6 @@ -78,9 +78,10 @@ export default DiscourseController.extend(ModalFunctionality, { var destinationUrl = $.cookie('destination_url'); $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') && destinationUrl) { + if ((self.get('loginRequired') || $.cookie('shouldRedirectToUrl')) && destinationUrl) { // redirect client to the original URL $.cookie('destination_url', null); + $.cookie('shouldRedirectToUrl', null); $hidden_login_form.find('input[name=redirect]').val(destinationUrl); } 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 4ce26ba27..9c26ce5c8 100644 --- a/app/assets/javascripts/discourse/routes/new-topic.js.es6 +++ b/app/assets/javascripts/discourse/routes/new-topic.js.es6 @@ -13,6 +13,7 @@ export default Discourse.Route.extend({ }); } else { // User is not logged in + $.cookie('shouldRedirectToUrl', true); self.replaceWith('login'); } } diff --git a/app/controllers/static_controller.rb b/app/controllers/static_controller.rb index d62882b50..b65f52b08 100644 --- a/app/controllers/static_controller.rb +++ b/app/controllers/static_controller.rb @@ -72,6 +72,7 @@ class StaticController < ApplicationController uri.path !~ /\./ destination = uri.path + destination = "#{uri.path}?#{uri.query}" if uri.path =~ /new-topic/ end rescue URI::InvalidURIError # Do nothing if the URI is invalid