Merge pull request #3045 from techAPJ/patch-2
FIX: redirect client to the original url after logging in for private in...
This commit is contained in:
commit
cdbee4f5d9
|
@ -8,6 +8,7 @@ export default DiscourseController.extend(ModalFunctionality, {
|
||||||
loggedIn: false,
|
loggedIn: false,
|
||||||
|
|
||||||
canLoginLocal: Discourse.computed.setting('enable_local_logins'),
|
canLoginLocal: Discourse.computed.setting('enable_local_logins'),
|
||||||
|
loginRequired: Em.computed.alias('controllers.application.loginRequired'),
|
||||||
|
|
||||||
resetForm: function() {
|
resetForm: function() {
|
||||||
this.set('authenticate', null);
|
this.set('authenticate', null);
|
||||||
|
@ -72,9 +73,16 @@ export default DiscourseController.extend(ModalFunctionality, {
|
||||||
self.set('loggedIn', true);
|
self.set('loggedIn', true);
|
||||||
// Trigger the browser's password manager using the hidden static login form:
|
// Trigger the browser's password manager using the hidden static login form:
|
||||||
var $hidden_login_form = $('#hidden-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=username]').val(self.get('loginName'));
|
||||||
$hidden_login_form.find('input[name=password]').val(self.get('loginPassword'));
|
$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();
|
$hidden_login_form.submit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -350,6 +350,8 @@ class ApplicationController < ActionController::Base
|
||||||
def redirect_to_login_if_required
|
def redirect_to_login_if_required
|
||||||
return if current_user || (request.format.json? && api_key_valid?)
|
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?
|
redirect_to :login if SiteSetting.login_required?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue