diff --git a/app/controllers/account_controller.rb b/app/controllers/account_controller.rb index 749fc8f642..0df4d102a9 100644 --- a/app/controllers/account_controller.rb +++ b/app/controllers/account_controller.rb @@ -19,7 +19,9 @@ class AccountController < ApplicationController helper :custom_fields + helper :account include CustomFieldsHelper + include AccountHelper self.main_menu = false @@ -33,7 +35,7 @@ class AccountController < ApplicationController authenticate_user else if User.current.logged? - redirect_back_or_default home_url, :referer => true + redirect_back_or_default start_page_url, :referer => true end end rescue AuthSourceException => e diff --git a/app/helpers/account_helper.rb b/app/helpers/account_helper.rb index 0e21b03288..6939e4dc10 100644 --- a/app/helpers/account_helper.rb +++ b/app/helpers/account_helper.rb @@ -18,4 +18,12 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. module AccountHelper + def start_page_url + start_page_candidates = { + 'home' => home_path, + 'my_page' => my_page_path, + 'projects' => projects_path + } + start_page_candidates[Setting.start_page] || home_path + end end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0e3f56c2ce..126c2ffc31 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1539,6 +1539,13 @@ module ApplicationHelper hidden_field_tag('back_url', url, :id => nil) unless url.blank? end + def back_url_after_login_hidden_field_tag + url = validate_back_url(back_url) + url = validate_back_url(start_page_url) if url == validate_back_url(home_url) + + hidden_field_tag('back_url', url, :id => nil) unless url.blank? + end + def cancel_button_tag(fallback_url) url = validate_back_url(back_url) || fallback_url link_to l(:button_cancel), url diff --git a/app/views/account/login.html.erb b/app/views/account/login.html.erb index 38991ae60d..0d45a47577 100644 --- a/app/views/account/login.html.erb +++ b/app/views/account/login.html.erb @@ -2,8 +2,8 @@
<%= form_tag(signin_path, onsubmit: 'return keepAnchorOnSignIn(this);') do %> - <%= back_url_hidden_field_tag %> - + <%= back_url_after_login_hidden_field_tag %> + <%= text_field_tag 'username', params[:username], :tabindex => '1' %> diff --git a/app/views/settings/_general.html.erb b/app/views/settings/_general.html.erb index 043067f180..673e658a37 100644 --- a/app/views/settings/_general.html.erb +++ b/app/views/settings/_general.html.erb @@ -6,6 +6,7 @@

<%= setting_text_area :welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %>

<%= wikitoolbar_for 'settings_welcome_text' %> +

<%= setting_select :start_page, [[l(:label_home), 'home'], [l(:label_my_page), 'my_page'], [l(:label_project_plural), 'projects']] %>

<%= setting_text_field :per_page_options, :size => 20 %> <%= l(:text_comma_separated) %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index 2378e56d5b..66e96832c5 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -413,6 +413,7 @@ en: setting_app_title: Application title setting_welcome_text: Welcome text + setting_start_page: Start page setting_default_language: Default language setting_login_required: Authentication required setting_self_registration: Self-registration diff --git a/config/settings.yml b/config/settings.yml index 0c41b7eda1..419c95d8b6 100644 --- a/config/settings.yml +++ b/config/settings.yml @@ -23,6 +23,8 @@ app_title: default: Redmine welcome_text: default: +start_page: + default: home login_required: default: 0 security_notifications: 1 diff --git a/test/functional/account_controller_test.rb b/test/functional/account_controller_test.rb index 93a434e40d..4c1377404f 100644 --- a/test/functional/account_controller_test.rb +++ b/test/functional/account_controller_test.rb @@ -37,12 +37,14 @@ class AccountControllerTest < Redmine::ControllerTest 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, - :params => { - :back_url => 'http://test.host/issues/show/1' - } - ) + with_settings :start_page => 'projects' do + get( + :login, + :params => { + :back_url => 'http://test.host/issues/show/1' + } + ) + end assert_redirected_to '/issues/show/1' assert_equal 2, @request.session[:user_id] end @@ -51,17 +53,24 @@ class AccountControllerTest < Redmine::ControllerTest @request.session[:user_id] = 2 @request.env["HTTP_REFERER"] = 'http://test.host/issues/show/1' - get :login + with_settings :start_page => 'projects' do + get :login + end 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 + def test_get_login_while_logged_in_should_redirect_to_start_page_by_default @request.session[:user_id] = 2 + start_pages = { 'projects' => '/projects', 'home' => '/', 'my_page' => '/my/page' } - get :login - assert_redirected_to '/' - assert_equal 2, @request.session[:user_id] + start_pages.each do |name, path| + with_settings :start_page => name do + get :login + assert_redirected_to path + assert_equal 2, @request.session[:user_id] + end + end end def test_login_should_redirect_to_back_url_param @@ -71,16 +80,18 @@ class AccountControllerTest < Redmine::ControllerTest 'http://test.host/', '/' ] - back_urls.each do |back_url| - post( - :login, - :params => { - :username => 'jsmith', - :password => 'jsmith', - :back_url => back_url - } - ) - assert_redirected_to back_url + with_settings :start_page => 'projects' do + back_urls.each do |back_url| + post( + :login, + :params => { + :username => 'jsmith', + :password => 'jsmith', + :back_url => back_url + } + ) + assert_redirected_to back_url + end end end @@ -92,16 +103,18 @@ class AccountControllerTest < Redmine::ControllerTest 'http://test.host/redmine/issues/show/1', '/redmine' ] - back_urls.each do |back_url| - post( - :login, - :params => { - :username => 'jsmith', - :password => 'jsmith', - :back_url => back_url - } - ) - assert_redirected_to back_url + with_settings :start_page => 'projects' do + back_urls.each do |back_url| + post( + :login, + :params => { + :username => 'jsmith', + :password => 'jsmith', + :back_url => back_url + } + ) + assert_redirected_to back_url + end end ensure Redmine::Utils.relative_url_root = @relative_url_root @@ -112,15 +125,17 @@ class AccountControllerTest < Redmine::ControllerTest 'http://test.foo/fake', '//test.foo/fake' ] - back_urls.each do |back_url| - post( - :login, :params => { - :username => 'jsmith', - :password => 'jsmith', - :back_url => back_url - } - ) - assert_redirected_to '/my/page' + with_settings :start_page => 'projects' do + back_urls.each do |back_url| + post( + :login, :params => { + :username => 'jsmith', + :password => 'jsmith', + :back_url => back_url + } + ) + assert_redirected_to '/my/page' + end end end @@ -144,16 +159,18 @@ class AccountControllerTest < Redmine::ControllerTest 'fake@test.foo', '.test.foo' ] - back_urls.each do |back_url| - post( - :login, - :params => { - :username => 'jsmith', - :password => 'jsmith', - :back_url => back_url - } - ) - assert_redirected_to '/my/page' + with_settings :start_page => 'projects' do + back_urls.each do |back_url| + post( + :login, + :params => { + :username => 'jsmith', + :password => 'jsmith', + :back_url => back_url + } + ) + assert_redirected_to '/my/page' + end end ensure Redmine::Utils.relative_url_root = @relative_url_root