Module: Authlogic::Session::Session

Defined in:
lib/authlogic/session/session.rb

Overview

Session

Handles all parts of authentication that deal with sessions. Such as persisting a session and saving / destroy a session.

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(klass) ⇒ Object



7
8
9
10
11
# File 'lib/authlogic/session/session.rb', line 7

def self.included(klass)
  klass.after_save :update_session!, :if => :persisting?
  klass.after_destroy :update_session!, :if => :persisting?
  klass.after_find :update_session!, :if => :persisting?
end

Instance Method Details

#valid_session?Boolean

Tries to validate the session from information in the session

Returns:

  • (Boolean)


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/authlogic/session/session.rb', line 14

def valid_session?
  persistence_token, record_id = session_credentials
  if !persistence_token.blank?
    if record_id
      record = search_for_record("find_by_id", record_id)
      self.unauthorized_record = record if record && record.send(persistence_token_field) == persistence_token
    else
      # For backwards compatibility, will eventually be removed, just need to let the sessions update theirself
      record = search_for_record("find_by_#{persistence_token_field}", persistence_token)
      if record
        controller.session["#{session_key}_id"] = record.send(record.class.primary_key)
        self.unauthorized_record = record
      end
    end
    return valid?
  end
  
  false
end