Module: Sorcery::Controller::Submodules::ActivityLogging

Defined in:
lib/sorcery/controller/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 controller part of the submodule, which adds hooks to register user events, and methods to collect active users data for use in the app. see Socery::Model::Submodules::ActivityLogging for configuration options.

Defined Under Namespace

Modules: InstanceMethods

Class Method Summary collapse

Class Method Details

.included(base) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/sorcery/controller/submodules/activity_logging.rb', line 15

def self.included(base)
  base.send(:include, InstanceMethods)
  Config.module_eval do
    class << self
      attr_accessor :register_login_time
      attr_accessor :register_logout_time
      attr_accessor :register_last_activity_time
      attr_accessor :register_last_ip_address

      def merge_activity_logging_defaults!
        @defaults.merge!(:@register_login_time         => true,
                         :@register_logout_time        => true,
                         :@register_last_activity_time => true,
                         :@register_last_ip_address    => true)
      end
    end
    merge_activity_logging_defaults!
  end

  Config. << :register_login_time_to_db
  Config. << :register_last_ip_address
  Config.before_logout << :register_logout_time_to_db

  base.after_action :register_last_activity_time_to_db
end