Module: Sorcery::Model::Submodules::ActivityLogging

Defined in:
lib/sorcery/model/submodules/activity_logging.rb

Overview

This submodule keeps track of events such as login, logout, and last activity time, per user. It helps in estimating which users are active now in the site. This cannot be determined absolutely because a user might be reading a page without clicking anything for a while. This is the model part of the submodule, which provides configuration options.

Defined Under Namespace

Modules: ClassMethods, InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/sorcery/model/submodules/activity_logging.rb', line 10

def self.included(base)
  base.extend(ClassMethods)
  base.send(:include, InstanceMethods)

  base.sorcery_config.class_eval do
    # last login attribute name.
    attr_accessor :last_login_at_attribute_name
    # last logout attribute name.
    attr_accessor :last_logout_at_attribute_name
    # last activity attribute name.
    attr_accessor :last_activity_at_attribute_name
    # last activity login source
    attr_accessor :last_login_from_ip_address_name
    # how long since last activity is the user defined offline
    attr_accessor :activity_timeout
  end

  base.sorcery_config.instance_eval do
    @defaults.merge!(:@last_login_at_attribute_name                => :last_login_at,
                     :@last_logout_at_attribute_name               => :last_logout_at,
                     :@last_activity_at_attribute_name             => :last_activity_at,
                     :@last_login_from_ip_address_name             => :last_login_from_ip_address,
                     :@activity_timeout                            => 10 * 60)
    reset!
  end

  base.sorcery_config.after_config << :define_activity_logging_fields
end