Sha256: 03173accd633fd547c38e3833febc51545665fa50e6043f20f6705eee4389520

Contents?: true

Size: 1.2 KB

Versions: 1

Compression:

Stored size: 1.2 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 < Devise::Strategies::Base
      # A valid strategy for rememberable needs a remember token in the cookies.
      def valid?
        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!
        if resource = mapping.to.serialize_from_cookie(*remember_cookie)
          success!(resource)
        else
          cookies.delete(remember_key)
          pass
        end
      end

    private

      def remember_key
        "remember_#{scope}_token"
      end

      # Accessor for remember cookie
      def remember_cookie
        @remember_cookie ||= cookies.signed[remember_key]
      end
    end
  end
end

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
devise-1.1.rc0 lib/devise/strategies/rememberable.rb