FIX: redirect client to the original url after logging in for private instances

This commit is contained in:
Arpit Jalan 2014-12-16 13:15:42 +05:30
parent 2020431fd8
commit 9f8e73303a
2 changed files with 11 additions and 1 deletions

View file

@ -8,6 +8,7 @@ export default DiscourseController.extend(ModalFunctionality, {
loggedIn: false,
canLoginLocal: Discourse.computed.setting('enable_local_logins'),
loginRequired: Em.computed.alias('controllers.application.loginRequired'),
resetForm: function() {
this.set('authenticate', null);
@ -72,9 +73,16 @@ export default DiscourseController.extend(ModalFunctionality, {
self.set('loggedIn', true);
// Trigger the browser's password manager using the hidden static login form:
var $hidden_login_form = $('#hidden-login-form');
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'));
$hidden_login_form.find('input[name=redirect]').val(window.location.href);
if (self.get('loginRequired') && destinationUrl) {
// redirect client to the original URL
$.cookie('destination_url', null);
$hidden_login_form.find('input[name=redirect]').val(destinationUrl);
} else {
$hidden_login_form.find('input[name=redirect]').val(window.location.href);
}
$hidden_login_form.submit();
}

View file

@ -346,6 +346,8 @@ class ApplicationController < ActionController::Base
def redirect_to_login_if_required
return if current_user || (request.format.json? && api_key_valid?)
# save original URL in a cookie
cookies[:destination_url] = request.original_url unless request.original_url =~ /uploads/
redirect_to :login if SiteSetting.login_required?
end