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
This commit is contained in:
parent
5faa1a4e6e
commit
a2f869b43e
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue