Sha256: 98948b6eeb34703fadf08e2944a3cc44904cf0e56e35f29df7df0613f2544066

Contents?: true

Size: 1.45 KB

Versions: 28

Compression:

Stored size: 1.45 KB

Contents

require 'devise/strategies/base'

module Devise
  module Strategies
    # Remember the user through the remember token. This strategy is responsible
    # to verify whether there is a cookie with the remember token, and to
    # recreate the user from this cookie if it exists. Must be called *before*
    # authenticatable.
    class Rememberable < Authenticatable
      # A valid strategy for rememberable needs a remember token in the cookies.
      def valid?
        @remember_cookie = nil
        remember_cookie.present?
      end

      # To authenticate a user we deserialize the cookie and attempt finding
      # the record in the database. If the attempt fails, we pass to another
      # strategy handle the authentication.
      def authenticate!
        resource = mapping.to.serialize_from_cookie(*remember_cookie)

        if validate(resource)
          success!(resource)
        elsif !halted?
          cookies.delete(remember_key)
          pass
        end
      end

    private

      def decorate(resource)
        super
        resource.extend_remember_period = mapping.to.extend_remember_period if resource.respond_to?(:extend_remember_period=)
      end

      def remember_me?
        true
      end

      def remember_key
        "remember_#{scope}_token"
      end

      def remember_cookie
        @remember_cookie ||= cookies.signed[remember_key]
      end

    end
  end
end

Warden::Strategies.add(:rememberable, Devise::Strategies::Rememberable)

Version data entries

28 entries across 28 versions & 4 rubygems

Version Path
devise-2.0.6 lib/devise/strategies/rememberable.rb
devise_sociable-0.1.0 vendor/bundle/gems/devise-1.5.4/lib/devise/strategies/rememberable.rb
devise-2.0.5 lib/devise/strategies/rememberable.rb
devise-1.5.4 lib/devise/strategies/rememberable.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/strategies/rememberable.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/strategies/rememberable.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/strategies/rememberable.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/strategies/rememberable.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/strategies/rememberable.rb
devise-2.1.0.rc lib/devise/strategies/rememberable.rb
devise-2.0.4 lib/devise/strategies/rememberable.rb
devise-2.0.2 lib/devise/strategies/rememberable.rb
devise-2.0.1 lib/devise/strategies/rememberable.rb
devise-2.0.0 lib/devise/strategies/rememberable.rb
devise-2.0.0.rc2 lib/devise/strategies/rememberable.rb
devise-2.0.0.rc lib/devise/strategies/rememberable.rb
devise-1.5.3 lib/devise/strategies/rememberable.rb
cloudfoundry-devise-1.5.2 lib/devise/strategies/rememberable.rb
devise-1.5.2 lib/devise/strategies/rememberable.rb
devise-1.5.1 lib/devise/strategies/rememberable.rb