Sha256: 8e4ff13ab721322af59aab3be1fa92ce2c8c1f6a9a9d7d27dff25e2d1a5bc110

Contents?: true

Size: 1.99 KB

Versions: 51

Compression:

Stored size: 1.99 KB

Contents

# -*- coding: utf-8 -*-
module Authentication
  module ByCookieToken
    # Stuff directives into including module 
    def self.included(recipient)
      recipient.extend(ModelClassMethods)
      recipient.class_eval do
        include ModelInstanceMethods
      end
    end

    #
    # Class Methods
    #
    module ModelClassMethods
    end # class methods

    #
    # Instance Methods
    #
    module ModelInstanceMethods
      def remember_token?
        (!remember_token.blank?) && 
          remember_token_expires_at && (Time.now.utc < remember_token_expires_at.utc)
      end

      # These create and unset the fields required for remembering users between browser closes
      def remember_me
        remember_me_for 2.weeks
      end

      def remember_me_for(time)
        remember_me_until time.from_now.utc
      end

      def remember_me_until(time)
        self.remember_token_expires_at = time
        self.remember_token            = self.class.make_token
        save(false)
      end

      # refresh token (keeping same expires_at) if it exists
      def refresh_token
        if remember_token?
          self.remember_token = self.class.make_token 
          save(false)      
        end
      end

      # 
      # Deletes the server-side record of the authentication token.  The
      # client-side (browser cookie) and server-side (this remember_token) must
      # always be deleted together.
      #
      def forget_me
        self.remember_token_expires_at = nil
        self.remember_token            = nil
        save(false)
      end
    end # instance methods
  end

  module ByCookieTokenController
    # Stuff directives into including module 
    def self.included( recipient )
      recipient.extend( ControllerClassMethods )
      recipient.class_eval do
        include ControllerInstanceMethods
      end
    end

    #
    # Class Methods
    #
    module ControllerClassMethods
    end # class methods
    
    module ControllerInstanceMethods
    end # instance methods
  end
end

Version data entries

51 entries across 51 versions & 7 rubygems

Version Path
genki-restful-authentication-1.1.1 lib/authentication/by_cookie_token.rb
smukherjee-openbill-0.1.5 vendor/plugins/restful-authentication/lib/authentication/by_cookie_token.rb
smukherjee-openbill-0.1.6 vendor/plugins/restful-authentication/lib/authentication/by_cookie_token.rb
smukherjee-openbill-0.1.7 vendor/plugins/restful-authentication/lib/authentication/by_cookie_token.rb
tournament-5.0.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
branston-0.6.6 lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
branston-0.6.5 lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
branston-0.6.4 lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
branston-0.6.3 lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
branston-0.6.2 lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-4.2.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-4.0.2 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-4.0.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
branston-0.6.1 lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
branston-0.6.0 lib/branston/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-3.3.3 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-3.3.2 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-3.3.1 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-3.3.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-3.2.2 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb