diff options
author | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-01-25 12:35:05 +0000 |
---|---|---|
committer | Jean-Philippe Lang <jp_lang@yahoo.fr> | 2014-01-25 12:35:05 +0000 |
commit | a2f869b43e0740656ba51a483d640d58e341c8ff (patch) | |
tree | 4ec135feb61d7fc570de2a223a3808d1534e734d | |
parent | 5faa1a4e6ed934e026a58a87de1e3f407ea99c97 (diff) | |
download | redmine-a2f869b43e0740656ba51a483d640d58e341c8ff.tar.gz redmine-a2f869b43e0740656ba51a483d640d58e341c8ff.zip |
Redirect to back_url or referer when clicking "Sign in" while already logged-in (#15926).
git-svn-id: http://svn.redmine.org/redmine/trunk@12705 e93f8b46-1217-0410-a6f0-8f06a7374b81
-rw-r--r-- | app/controllers/account_controller.rb | 2 | ||||
-rw-r--r-- | app/controllers/application_controller.rb | 5 | ||||
-rw-r--r-- | test/functional/account_controller_test.rb | 20 |
3 files changed, 24 insertions, 3 deletions
diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index a3768d403..034821107 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -34,7 +34,7 @@ class AccountController < ApplicationController def login if request.get? if User.current.logged? - redirect_to home_url + redirect_back_or_default home_url, :referer => true end else authenticate_user diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 152dc3f18..c4b01ed40 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -373,7 +373,7 @@ class ApplicationController < ActionController::Base url end - def redirect_back_or_default(default) + def redirect_back_or_default(default, options={}) back_url = params[:back_url].to_s if back_url.present? begin @@ -387,6 +387,9 @@ class ApplicationController < ActionController::Base logger.warn("Could not redirect to invalid URL #{back_url}") # redirect to default end + elsif options[:referer] + redirect_to_referer_or default + return end redirect_to default false diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 5423e065b..738371ab4 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -33,7 +33,25 @@ class AccountControllerTest < ActionController::TestCase assert_select 'input[name=password]' end - def test_get_login_while_logged_in_should_redirect_to_home + def test_get_login_while_logged_in_should_redirect_to_back_url_if_present + @request.session[:user_id] = 2 + @request.env["HTTP_REFERER"] = 'http://test.host/issues/show/1' + + get :login, :back_url => 'http://test.host/issues/show/1' + assert_redirected_to '/issues/show/1' + assert_equal 2, @request.session[:user_id] + end + + def test_get_login_while_logged_in_should_redirect_to_referer_without_back_url + @request.session[:user_id] = 2 + @request.env["HTTP_REFERER"] = 'http://test.host/issues/show/1' + + get :login + assert_redirected_to '/issues/show/1' + assert_equal 2, @request.session[:user_id] + end + + def test_get_login_while_logged_in_should_redirect_to_home_by_default @request.session[:user_id] = 2 get :login |