Sha256: da8d3826044f08fb693a8c9d003234e4053fbcfb5bf4c94ed2cc586741421b70

Contents?: true

Size: 1.32 KB

Versions: 1

Compression:

Stored size: 1.32 KB

Contents

module AuthTrail
  module Manager
    class << self
      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

      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
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
authtrail-0.1.0 lib/auth_trail/manager.rb