Sha256: dfdad6103bb2fb94fbc1086bce5f979fa7b10254db4d835f165283113bff89bc

Contents?: true

Size: 1.18 KB

Versions: 32

Compression:

Stored size: 1.18 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_me_cookie.present? && mapping.to.respond_to?(:serialize_from_cookie)
      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_me_cookie)
          success!(resource)
        else
          pass
        end
      end

    private

      # Accessor for remember cookie
      def remember_me_cookie
        @remember_me_cookie ||= request.cookies["remember_#{mapping.name}_token"]
      end
    end
  end
end

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

Version data entries

32 entries across 27 versions & 7 rubygems

Version Path
graffititracker_devise-1.0.11 lib/devise/strategies/rememberable.rb
devise-1.0.11 lib/devise/strategies/rememberable.rb
devise-1.0.10 lib/devise/strategies/rememberable.rb
devise_ennder-1.4.1.0.9 test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb
devise_ennder-1.4.1.0.9 lib/devise/strategies/rememberable.rb
devise_ennder-1.3.1.0.9 lib/devise/strategies/rememberable.rb
devise_ennder-1.3.1.0.9 test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb
devise_ennder-1.2.1.0.9 test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb
devise_ennder-1.2.1.0.9 lib/devise/strategies/rememberable.rb
devise_ennder-1.1.1.0.9 lib/devise/strategies/rememberable.rb
devise_ennder-1.1.1.0.9 test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb
devise_ennder-1.0.1.0.9 test/rails_app/vendor/plugins/devise/lib/devise/strategies/rememberable.rb
devise_ennder-1.0.1.0.9 lib/devise/strategies/rememberable.rb
devise-1.0.9 lib/devise/strategies/rememberable.rb
dcu-devise-1.0.7 lib/devise/strategies/rememberable.rb
devise-1.0.8 lib/devise/strategies/rememberable.rb
ivanvc-devise-1.0.7.1 lib/devise/strategies/rememberable.rb
mongoid-devise-1.0.1 lib/devise/strategies/rememberable.rb
devise-1.0.7 lib/devise/strategies/rememberable.rb
devise-1.0.6 lib/devise/strategies/rememberable.rb