Sha256: 4f8ed0b7e4044762e2124edd9258086d560e5f3d33e47879cca43612a1fea02e

Contents?: true

Size: 1.21 KB

Versions: 14

Compression:

Stored size: 1.21 KB

Contents

require 'devise/hooks/timeoutable'

module Devise
  module Models
    # Timeoutable takes care of veryfing whether a user session has already
    # expired or not. When a session expires after the configured time, the user
    # will be asked for credentials again, it means, he/she will be redirected
    # to the sign in page.
    #
    # == Options
    #
    # Timeoutable adds the following options to devise_for:
    #
    #   * +timeout_in+: the interval to timeout the user session without activity.
    #
    # == Examples
    #
    #   user.timedout?(30.minutes.ago)
    #
    module Timeoutable
      extend ActiveSupport::Concern

      # Checks whether the user session has expired based on configured time.
      def timedout?(last_access)
        return false if remember_exists_and_not_expired?
        !timeout_in.nil? && last_access && last_access <= timeout_in.ago
      end

      def timeout_in
        self.class.timeout_in
      end

      private

      def remember_exists_and_not_expired?
        return false unless respond_to?(:remember_created_at)
        remember_created_at && !remember_expired?
      end

      module ClassMethods
        Devise::Models.config(self, :timeout_in)
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 3 rubygems

Version Path
devise-2.0.6 lib/devise/models/timeoutable.rb
devise-2.0.5 lib/devise/models/timeoutable.rb
sunrise-cms-0.3.3 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/models/timeoutable.rb
sunrise-cms-0.3.2 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/models/timeoutable.rb
sunrise-cms-0.3.1 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/models/timeoutable.rb
sunrise-cms-0.3.0 vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/models/timeoutable.rb
sunrise-cms-0.3.0.rc vendor/bundle/ruby/1.9.1/gems/devise-2.0.4/lib/devise/models/timeoutable.rb
devise-2.0.4 lib/devise/models/timeoutable.rb
devise-2.0.2 lib/devise/models/timeoutable.rb
devise-2.0.1 lib/devise/models/timeoutable.rb
devise-2.0.0 lib/devise/models/timeoutable.rb
devise-2.0.0.rc2 lib/devise/models/timeoutable.rb
devise-2.0.0.rc lib/devise/models/timeoutable.rb
cloudfoundry-devise-1.5.2 lib/devise/models/timeoutable.rb