Module: Authlogic::Session::Timeout
- Included in:
- Base
- Defined in:
- lib/authlogic/session/timeout.rb
Overview
Timeout
This is reponsibile for determining if the session is stale or fresh. It is also responsible for maintaining the last_request_at value if the column is present.
Think about how financial websites work. If you are inactive after a certain period of time you must log back in. By default this is disabled, but if enabled this module kicks in. See the logout_on_timeout configuration option for how to turn this on.
Class Method Summary collapse
Instance Method Summary collapse
-
#find_record_with_timeout ⇒ Object
This implements the stale functionality when trying to find a session.
-
#stale? ⇒ Boolean
Tells you if the record is stale or not.
Class Method Details
.included(klass) ⇒ Object
10 11 12 13 14 15 16 17 |
# File 'lib/authlogic/session/timeout.rb', line 10 def self.included(klass) klass.class_eval do alias_method_chain :find_record, :timeout before_find :reset_stale_state after_find :set_last_request_at before_save :set_last_request_at end end |
Instance Method Details
#find_record_with_timeout ⇒ Object
This implements the stale functionality when trying to find a session. If the session is stale the record will be cleared, but the session object will still be returned. This allows you to perform a current_user_session.stale? query in order to inform your users of why they need to log back in.
21 22 23 24 25 26 27 28 |
# File 'lib/authlogic/session/timeout.rb', line 21 def find_record_with_timeout result = find_record_without_timeout if result && stale? self.record = nil @stale = true end result end |
#stale? ⇒ Boolean
Tells you if the record is stale or not. Meaning the record has timed out. This will only return true if you set logout_on_timeout to true in your configuration. Basically how a bank website works. If you aren’t active over a certain period of time your session becomes stale and requires you to log back in.
32 33 34 |
# File 'lib/authlogic/session/timeout.rb', line 32 def stale? @stale == true || (logout_on_timeout? && record && record.logged_out?) end |