Module: AuthTrail::Manager

Defined in:
lib/auth_trail/manager.rb

Class Method Summary collapse

Class Method Details

.after_set_user(user, auth, opts) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/auth_trail/manager.rb', line 4

def after_set_user(user, auth, opts)
  # do not raise an exception for tracking
  AuthTrail.safely do
    request = ActionDispatch::Request.new(auth.env)

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

    identity = user.try(:email)
    AuthTrail.track(
      strategy: strategy,
      scope: opts[:scope].to_s,
      identity: identity,
      success: true,
      request: request,
      user: user
    )
  end
end

.before_failure(env, opts) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/auth_trail/manager.rb', line 25

def before_failure(env, opts)
  AuthTrail.safely do
    if opts[:message]
      request = ActionDispatch::Request.new(env)
      identity = request.params[opts[:scope]] && request.params[opts[:scope]][:email] rescue nil

      AuthTrail.track(
        strategy: "database_authenticatable",
        scope: opts[:scope].to_s,
        identity: identity,
        success: false,
        request: request,
        failure_reason: opts[:message].to_s
      )
    end
  end
end