Sha256: 7536e0220bc1bf547494d3b561f8810b4234e4917a199a33329df9c3f59a6ced

Contents?: true

Size: 1.54 KB

Versions: 1

Compression:

Stored size: 1.54 KB

Contents

require 'authenticate/callbacks/timeoutable'

module Authenticate
  module Model

    # Expire user sessions that have not been accessed within a certain period of time.
    # Expired users will be asked for credentials again.
    #
    # == Columns
    #
    # This module expects and tracks this column on your user model:
    # - last_access_at - timestamp of the last access by the user
    #
    # == Configuration
    #
    # Timeoutable is enabled and configured with the `timeout_in` configuration parameter.
    # `timeout_in` expects a timestamp. Example:
    #
    #   Authenticate.configure do |config|
    #     config.timeout_in = 15.minutes
    #   end
    #
    # You must specify a non-nil timeout_in in your initializer to enable Timeoutable.
    #
    module Timeoutable
        extend ActiveSupport::Concern

        def self.required_fields(klass)
          [:last_access_at]
        end

        # Checks whether the user session has expired based on configured time.
        def timedout?
          Rails.logger.info "User.timedout? timeout_in:#{timeout_in}  last_access_at:#{last_access_at}"
          return false if timeout_in.nil?
          return false if last_access_at.nil?
          # result = Time.now.utc > (last_access_at + timeout_in)
          Rails.logger.info "User.timedout? #{last_access_at >= timeout_in.ago}   timeout_in.ago:#{timeout_in.ago}  last_access_at:#{last_access_at}"
          last_access_at <= timeout_in.ago
        end

        def timeout_in
          Authenticate.configuration.timeout_in
        end
      end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authenticate-0.1.0 lib/authenticate/model/timeoutable.rb