Sha256: 7ad3cadfc3284ed90cbd177a444341c5991c549bc316e4fd775e4f76af0f40d7

Contents?: true

Size: 1.99 KB

Versions: 17

Compression:

Stored size: 1.99 KB

Contents

# -*- coding: mule-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

17 entries across 17 versions & 5 rubygems

Version Path
caleb-restful-authentication-1.1.1 lib/authentication/by_cookie_token.rb
dwaite-restful-authentication-1.1.1 lib/authentication/by_cookie_token.rb
ggoodale-restful-authentication-1.1.1 lib/authentication/by_cookie_token.rb
simonmenke-mr_authentication-0.0.1 vendor/plugins/restful-authentication/lib/authentication/by_cookie_token.rb
tournament-2.1.1 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.2.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.1.2 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.2.1 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.0.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.1.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.2.2 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.4.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.5.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.3.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.6.0 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.5.2 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb
tournament-2.5.1 webgui/vendor/plugins/restful_authentication/lib/authentication/by_cookie_token.rb