Feature #664 » feature-664.patch
| app/controllers/account_controller.rb | ||
|---|---|---|
|
class AccountController < ApplicationController
|
||
|
helper :custom_fields
|
||
|
helper :account
|
||
|
include CustomFieldsHelper
|
||
|
include AccountHelper
|
||
|
self.main_menu = false
|
||
| ... | ... | |
|
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
|
||
| app/helpers/account_helper.rb | ||
|---|---|---|
|
# 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
|
||
| app/helpers/application_helper.rb | ||
|---|---|---|
|
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
|
||
| app/views/account/login.html.erb | ||
|---|---|---|
|
<div id="login-form">
|
||
|
<%= form_tag(signin_path, onsubmit: 'return keepAnchorOnSignIn(this);') do %>
|
||
|
<%= back_url_hidden_field_tag %>
|
||
|
|
||
|
<%= back_url_after_login_hidden_field_tag %>
|
||
|
<label for="username"><%=l(:field_login)%></label>
|
||
|
<%= text_field_tag 'username', params[:username], :tabindex => '1' %>
|
||
|
|
||
| app/views/settings/_general.html.erb | ||
|---|---|---|
|
<p><%= setting_text_area :welcome_text, :cols => 60, :rows => 5, :class => 'wiki-edit' %></p>
|
||
|
<%= wikitoolbar_for 'settings_welcome_text' %>
|
||
|
<p><%= setting_select :start_page, [[l(:label_home), 'home'], [l(:label_my_page), 'my_page'], [l(:label_project_plural), 'projects']] %></p>
|
||
|
<p><%= setting_text_field :per_page_options, :size => 20 %>
|
||
|
<em class="info"><%= l(:text_comma_separated) %></em></p>
|
||
| config/locales/en.yml | ||
|---|---|---|
|
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
|
||
| config/settings.yml | ||
|---|---|---|
|
default: Redmine
|
||
|
welcome_text:
|
||
|
default:
|
||
|
start_page:
|
||
|
default: home
|
||
|
login_required:
|
||
|
default: 0
|
||
|
security_notifications: 1
|
||
| test/functional/account_controller_test.rb | ||
|---|---|---|
|
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
|
||
| ... | ... | |
|
@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
|
||
| ... | ... | |
|
'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
|
||
| ... | ... | |
|
'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
|
||
| ... | ... | |
|
'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
|
||
| ... | ... | |
|
'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
|
||