Sha256: 2ac5f8956675860b66097b0f92a65f450c92fb460d5bd12f76f1dedd99e65ae0

Contents?: true

Size: 1.08 KB

Versions: 1

Compression:

Stored size: 1.08 KB

Contents

module Authlogic
  module Session
    # = Cookies
    #
    # Handles all authentication that deals with cookies, such as persisting a session and saving / destroying a session.
    module Cookies
      def self.included(klass)
        klass.after_save :save_cookie, :if => :persisting?
        klass.after_destroy :destroy_cookie, :if => :persisting?
      end
      
      # Tries to validate the session from information in the cookie
      def valid_cookie?
        if cookie_credentials
          self.unauthorized_record = search_for_record("find_by_#{persistence_token_field}", cookie_credentials)
          valid? && !stale?
        else
          false
        end
      end
      
      private
        def cookie_credentials
          controller.cookies[cookie_key]
        end
        
        def save_cookie
          controller.cookies[cookie_key] = {
            :value => record.send(persistence_token_field),
            :expires => remember_me_until
          }
        end
        
        def destroy_cookie
          controller.cookies.delete cookie_key
        end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authlogic-1.3.9 lib/authlogic/session/cookies.rb