Refactor session expire method

This commit is contained in:
Andrius Janauskas 2013-09-13 16:01:54 +03:00
parent 0e3000b2c5
commit 0150e9f2c3

View file

@ -45,23 +45,20 @@ class ApplicationController < ActionController::Base
def set_session_expiration def set_session_expiration
# http://wiki.rubyonrails.com/rails/show/HowtoChangeSessionOptions # http://wiki.rubyonrails.com/rails/show/HowtoChangeSessionOptions
unless session == nil # If the method is called by the feed controller (which we don't have
return if self.controller_name == 'feed' or session['noexpiry'] == "on" # under session control) or if we checked the box to keep logged in on
# If the method is called by the feed controller (which we don't have # login don't set the session expiry time.
# under session control) or if we checked the box to keep logged in on return if session.nil? || self.controller_name == 'feed' || session['noexpiry'] == "on"
# login don't set the session expiry time.
if session # Get expiry time (allow ten seconds window for the case where we have
# Get expiry time (allow ten seconds window for the case where we have # none)
# none) expiry_time = session['expiry_time'] || Time.now + 10
expiry_time = session['expiry_time'] || Time.now + 10 if expiry_time < Time.now
if expiry_time < Time.now # Too late, matey... bang goes your session!
# Too late, matey... bang goes your session! reset_session
reset_session else
else # Okay, you get another hour
# Okay, you get another hour session['expiry_time'] = Time.now + (60*60)
session['expiry_time'] = Time.now + (60*60)
end
end
end end
end end