def session_expiration
if session[:user_id]
if session_expired? && !try_to_autologin
+ set_localization(User.active.find_by_id(session[:user_id]))
reset_session
flash[:error] = l(:error_session_expired)
redirect_to signin_url
end
end
- def set_localization
+ def set_localization(user=User.current)
lang = nil
- if User.current.logged?
- lang = find_language(User.current.language)
+ if user && user.logged?
+ lang = find_language(user.language)
end
if lang.nil? && !Setting.force_default_language_for_anonymous? && request.env['HTTP_ACCEPT_LANGUAGE']
accept_lang = parse_qvalues(request.env['HTTP_ACCEPT_LANGUAGE']).first
end
class SessionsTest < ActionController::TestCase
+ include Redmine::I18n
tests WelcomeController
fixtures :users
end
end
+ def test_expired_user_session_should_set_locale
+ set_language_if_valid 'it'
+ user = User.find(2)
+ user.language = 'fr'
+ user.save!
+
+ with_settings :session_timeout => '60' do
+ get :index, {}, {:user_id => user.id, :atime => 4.hours.ago.utc.to_i}
+ assert_redirected_to '/login'
+ assert_include "Veuillez vous reconnecter", flash[:error]
+ assert_equal :fr, current_language
+ end
+ end
+
def test_anonymous_session_should_not_be_reset
with_settings :session_lifetime => '720', :session_timeout => '60' do
get :index