FIX: use session instead of cookie to preserve url

This commit is contained in:
Arpit Jalan 2015-06-16 11:38:48 +05:30
parent d37c2a2c98
commit 4628b06fd6
2 changed files with 6 additions and 3 deletions

View File

@ -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);
}

View File

@ -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');
}
}