diff options
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 48 |
1 files changed, 39 insertions, 9 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 6d14d0d7a..239145944 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -14,8 +14,14 @@ class ApplicationController < ActionController::Base # Standard headers, footers and navigation for whole site layout "default" include FastGettext::Translation # make functions like _, n_, N_ etc available) + + # Note: a filter stops the chain if it redirects or renders something + before_filter :authentication_check before_filter :set_gettext_locale + before_filter :check_in_post_redirect + before_filter :session_remember_me before_filter :set_vary_header + # scrub sensitive parameters from the logs filter_parameter_logging :password @@ -48,7 +54,14 @@ class ApplicationController < ActionController::Base else requested_locale = params[:locale] || session[:locale] || cookies[:locale] || I18n.default_locale end + requested_locale = FastGettext.best_locale_in(requested_locale) session[:locale] = FastGettext.set_locale(requested_locale) + if !@user.nil? + if @user.locale != requested_locale + @user.locale = session[:locale] + @user.save! + end + end end # scrub sensitive parameters from the logs @@ -85,7 +98,6 @@ class ApplicationController < ActionController::Base # Set cookie expiry according to "remember me" checkbox, as per "An easier # and more flexible hack" on this page: # http://wiki.rubyonrails.org/rails/pages/HowtoChangeSessionOptions - before_filter :session_remember_me def session_remember_me # Reset the "sliding window" session expiry time. if request.env['rack.session.options'] @@ -199,7 +211,9 @@ class ApplicationController < ActionController::Base post_redirect = PostRedirect.new(:uri => request.request_uri, :post_params => params, :reason_params => reason_params) post_redirect.save! - redirect_to signin_url(:token => post_redirect.token) + # 'modal' controls whether the sign-in form will be displayed in the typical full-blown + # page or on its own, useful for pop-ups + redirect_to signin_url(:token => post_redirect.token, :modal => params[:modal]) return false end return true @@ -263,7 +277,6 @@ class ApplicationController < ActionController::Base end # If we are in a faked redirect to POST request, then set post params. - before_filter :check_in_post_redirect def check_in_post_redirect if params[:post_redirect] and session[:post_redirect_token] post_redirect = PostRedirect.find_by_token(session[:post_redirect_token]) @@ -272,7 +285,6 @@ class ApplicationController < ActionController::Base end # Default layout shows user in corner, so needs access to it - before_filter :authentication_check def authentication_check if session[:user_id] @user = authenticated_user @@ -346,14 +358,18 @@ class ApplicationController < ActionController::Base return (params[:page] || "1").to_i end - # Store last visited pages, for contact form + # Store last visited pages, for contact form; but only for logged in users, as otherwise this breaks caching def set_last_request(info_request) - session[:last_request_id] = info_request.id - session[:last_body_id] = nil + if !session[:user_id].nil? + session[:last_request_id] = info_request.id + session[:last_body_id] = nil + end end def set_last_body(public_body) - session[:last_request_id] = nil - session[:last_body_id] = public_body.id + if !session[:user_id].nil? + session[:last_request_id] = nil + session[:last_body_id] = public_body.id + end end def param_exists(item) @@ -472,6 +488,20 @@ class ApplicationController < ActionController::Base # Site-wide access to configuration settings include ConfigHelper + + # XXX: patch to improve usability of gettext's _(), which by default accepts only + # one parameter. This is normally done in a monkey patch file named 'i18n_fixes.rb'. + # For some reason - and only when running in production -, after adding a new controller + # in a theme, the monkey patch in 'i18n_fixes.rb' doesn't seem to take effect. + # But it works just fine in the views. + # It's probably related to the loading order of classes, but including the + # monkey patch before or after the theme makes no difference. Even more bizarrely, + # require'ing or load'ing the patch file here doesn't work (!?), I need to redefine + # the method explicitely. I'm going crazy... + def _(key, options = {}) + translation = FastGettext._(key) || key + gettext_interpolate(translation, options) + end end |