Module: Devise::AuditLog

Defined in:
lib/devise/audit_log.rb,
lib/devise/audit-log/version.rb

Constant Summary collapse

VERSION =
"0.1.2"
@@test =
true

Class Method Summary collapse

Class Method Details

.account_locked_eventObject



61
62
63
# File 'lib/devise/audit_log.rb', line 61

def self.
  "ACCOUNT LOCKED".freeze
end

.account_unlocked_eventObject



57
58
59
# File 'lib/devise/audit_log.rb', line 57

def self.
  "ACCOUNT UNLOCKED".freeze
end

.log(event, user, warden, env, options, success) ⇒ Object



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
# File 'lib/devise/audit_log.rb', line 11

def self.log(event, user, warden, env, options, success)
  env ||= warden.try(:env)
  warden ||= env["warden"] if env

  request = ActionDispatch::Request.new(env)

  ael = AuthenticationEventLog.new

  ael.event_type = event
  ael.user = user
  ael.ip = request.remote_ip if env
  ael.user_agent = request.user_agent if env
  ael.referrer = request.referrer if env
  ael.scope = options[:scope].to_s
  ael.strategy = AuditLog.warden_strategy(warden) if warden

  ael.success = success
  ael.failure_reason = options[:message].to_s if !ael.success

  ael.identity = user.try(:email) || request.params[ ael.scope ] && request.params[ ael.scope ][:email] || nil

  ael.action = "#{request.params[:controller]}##{request.params[:action]}" if request && env && request.params.has_key?(:controller)

  ael.save
end

.login_eventObject



45
46
47
# File 'lib/devise/audit_log.rb', line 45

def self.
  "LOGIN".freeze
end

.login_failure_eventObject



53
54
55
# File 'lib/devise/audit_log.rb', line 53

def self.
  "LOGIN FAILURE".freeze
end

.logout_eventObject



49
50
51
# File 'lib/devise/audit_log.rb', line 49

def self.logout_event
  "LOGOUT".freeze
end

.password_change_eventObject



73
74
75
# File 'lib/devise/audit_log.rb', line 73

def self.password_change_event
  "PASSWORD CHANGED".freeze
end

.password_reset_eventObject



65
66
67
# File 'lib/devise/audit_log.rb', line 65

def self.password_reset_event
  "PASSWORD RESET".freeze
end

.password_reset_sent_eventObject



69
70
71
# File 'lib/devise/audit_log.rb', line 69

def self.password_reset_sent_event
  "PASSWORD RESET SENT".freeze
end

.warden_strategy(warden_env) ⇒ Object



38
39
40
41
42
43
# File 'lib/devise/audit_log.rb', line 38

def self.warden_strategy(warden_env)
  strategy = warden_env.env["omniauth.auth"]["provider"] if warden_env.env["omniauth.auth"]
  strategy ||= warden_env.winning_strategy.class.name.split("::").last.underscore if warden_env.winning_strategy
  strategy ||= "database_authenticatable"
  strategy
end