lib/authtrail.rb in authtrail-0.1.1 vs lib/authtrail.rb in authtrail-0.1.2
- old
+ new
@@ -7,26 +7,37 @@
require "auth_trail/manager"
require "auth_trail/version"
module AuthTrail
class << self
- attr_accessor :exclude_method, :geocode, :track_method
+ attr_accessor :exclude_method, :geocode, :track_method, :identity_method
end
self.geocode = true
+ self.identity_method = lambda do |request, opts, user|
+ if user
+ user.try(:email)
+ else
+ scope = opts[:scope]
+ request.params[scope] && request.params[scope][:email] rescue nil
+ end
+ end
def self.track(strategy:, scope:, identity:, success:, request:, user: nil, failure_reason: nil)
info = {
strategy: strategy,
scope: scope,
identity: identity,
success: success,
failure_reason: failure_reason,
user: user,
- context: "#{request.params[:controller]}##{request.params[:action]}",
ip: request.remote_ip,
user_agent: request.user_agent,
referrer: request.referrer
}
+
+ if request.params[:controller]
+ info[:context] = "#{request.params[:controller]}##{request.params[:action]}"
+ end
# if exclude_method throws an exception, default to not excluding
exclude = AuthTrail.exclude_method && AuthTrail.safely(default: false) { AuthTrail.exclude_method.call(info) }
unless exclude