Sha256: bff2f5179fd6b712b6238d04a54c9f7bb204c2303b4ef85500185d43fde0cb86

Contents?: true

Size: 1.65 KB

Versions: 27

Compression:

Stored size: 1.65 KB

Contents

module Devise
  module Controllers
    # A module that may be optionally included in a controller in order
    # to provide remember me behavior.
    module Rememberable
      # Return default cookie values retrieved from session options.
      def self.cookie_values
        Rails.configuration.session_options.slice(:path, :domain, :secure)
      end

      # A small warden proxy so we can remember and forget uses from hooks.
      class Proxy #:nodoc:
        include Devise::Controllers::Rememberable

        delegate :cookies, :env, :to => :@warden

        def initialize(warden)
          @warden = warden
        end
      end

      # Remembers the given resource by setting up a cookie
      def remember_me(resource)
        scope = Devise::Mapping.find_scope!(resource)
        resource.remember_me!(resource.extend_remember_period)
        cookies.signed["remember_#{scope}_token"] = remember_cookie_values(resource)
      end

      # Forgets the given resource by deleting a cookie
      def forget_me(resource)
        scope = Devise::Mapping.find_scope!(resource)
        resource.forget_me!
        cookies.delete("remember_#{scope}_token", forget_cookie_values(resource))
      end

      protected

      def forget_cookie_values(resource)
        Devise::Controllers::Rememberable.cookie_values.merge!(resource.rememberable_options)
      end

      def remember_cookie_values(resource)
        options = { :httponly => true }
        options.merge!(forget_cookie_values(resource))
        options.merge!(
          :value => resource.class.serialize_into_cookie(resource),
          :expires => resource.remember_expires_at
        )
      end
    end
  end
end

Version data entries

27 entries across 22 versions & 5 rubygems

Version Path
devise-2.0.6 lib/devise/controllers/rememberable.rb
devise-2.1.4 lib/devise/controllers/rememberable.rb
devise-2.1.3 lib/devise/controllers/rememberable.rb
devise-2.0.5 lib/devise/controllers/rememberable.rb
devise-2.2.2 lib/devise/controllers/rememberable.rb
devise-2.2.1 lib/devise/controllers/rememberable.rb
devise-2.2.0 lib/devise/controllers/rememberable.rb
sunrise-cms-0.5.0.rc1 vendor/bundle/ruby/1.9.1/gems/devise-2.2.0.rc/lib/devise/controllers/rememberable.rb
devise-2.2.0.rc lib/devise/controllers/rememberable.rb
af-devise-2.1.2 lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/devise-2.1.0/lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/devise-2.1.0/lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/devise-2.1.0/lib/devise/controllers/rememberable.rb
devise-2.1.2 lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/devise-2.1.0/lib/devise/controllers/rememberable.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/controllers/rememberable.rb
rmello-devise-2.1.0.2 lib/devise/controllers/rememberable.rb