diff options
author | Louise Crow <louise.crow@gmail.com> | 2014-12-15 10:44:19 +0000 |
---|---|---|
committer | Louise Crow <louise.crow@gmail.com> | 2014-12-15 10:44:19 +0000 |
commit | 0e5726a1de7bf927a4ef99a98267b90beffb4746 (patch) | |
tree | c53cfda3eed152070e8df62477dcbcd76f849e79 /app/controllers/application_controller.rb | |
parent | 64e636fee3651f5f6c9d3e34bd1260d546e11ce7 (diff) | |
parent | 224725e202d581d956e8958c521abb00de9935b1 (diff) |
Merge branch 'misc-fixes' into rails-3-develop
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r-- | app/controllers/application_controller.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 1ccf7e5db..a06fa7098 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -30,6 +30,8 @@ class ApplicationController < ActionController::Base before_filter :check_in_post_redirect before_filter :session_remember_me before_filter :set_vary_header + before_filter :validate_session_timestamp + after_filter :persist_session_timestamp def set_vary_header response.headers['Vary'] = 'Cookie' @@ -121,6 +123,29 @@ class ApplicationController < ActionController::Base end end + # Set a TTL for non "remember me" sessions so that the cookie + # is not replayable forever + SESSION_TTL = 3.hours + def validate_session_timestamp + if session[:user_id] && session.key?(:ttl) && session[:ttl] < SESSION_TTL.ago + clear_session_credentials + redirect_to signin_path + end + end + + def persist_session_timestamp + session[:ttl] = Time.now if session[:user_id] && !session[:remember_me] + end + + # Logout form + def clear_session_credentials + session[:user_id] = nil + session[:user_circumstance] = nil + session[:remember_me] = false + session[:using_admin] = nil + session[:admin_name] = nil + end + def render_exception(exception) # In development or the admin interface let Rails handle the exception # with its stack trace templates |