Sha256: e31415200db260cc58f7c6e6431bb3b74c7608ad1067172e43bf5d8e38cad049

Contents?: true

Size: 1.07 KB

Versions: 11

Compression:

Stored size: 1.07 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)
          return valid?
        end
        
        false
      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

11 entries across 11 versions & 1 rubygems

Version Path
authlogic-1.3.2 lib/authlogic/session/cookies.rb
authlogic-1.2.1 lib/authlogic/session/cookies.rb
authlogic-1.3.1 lib/authlogic/session/cookies.rb
authlogic-1.3.0 lib/authlogic/session/cookies.rb
authlogic-1.2.2 lib/authlogic/session/cookies.rb
authlogic-1.3.7 lib/authlogic/session/cookies.rb
authlogic-1.3.8 lib/authlogic/session/cookies.rb
authlogic-1.3.3 lib/authlogic/session/cookies.rb
authlogic-1.3.4 lib/authlogic/session/cookies.rb
authlogic-1.3.5 lib/authlogic/session/cookies.rb
authlogic-1.3.6 lib/authlogic/session/cookies.rb