2012-01-30 20:39:34 +00:00
|
|
|
# -*- encoding : utf-8 -*-
|
2011-10-14 21:45:58 +01:00
|
|
|
Warden::Manager.after_authentication do |user,auth,opts| # after_set_user, :except => fetch
|
2012-04-26 02:38:33 +01:00
|
|
|
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => user)
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
Warden::Manager.before_failure do |env, opts|
|
|
|
|
# raise env.inspect
|
2011-10-29 15:50:22 +01:00
|
|
|
ActiveSupport::Notifications.instrument "event_log.observer", :kind => 'error',
|
|
|
|
:message => (env['action_dispatch.request.request_parameters']['user'].delete_if{|k,v| k == 'password'}.inspect rescue nil)
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
Warden::Manager.before_logout do |user,auth,opts|
|
2012-04-26 02:38:33 +01:00
|
|
|
ActiveSupport::Notifications.instrument("event_log.observer", :eventable => user)
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
ActiveSupport::Notifications.subscribe "event_log.observer" do |name, start, finish, id, payload|
|
|
|
|
if c = EventLog.current_controller
|
2012-04-26 02:38:33 +01:00
|
|
|
eventable = payload[:eventable]
|
|
|
|
message = payload[:message].presence; message ||= eventable.event_log_message if eventable.respond_to?(:event_log_message)
|
2011-10-29 15:50:22 +01:00
|
|
|
EventLog.create_with_current_controller :kind => (payload[:kind].presence || 'info'), :message => message,
|
2012-04-26 02:38:33 +01:00
|
|
|
:eventable => eventable, :eventable_name => payload[:eventable_name].presence
|
2011-10-14 21:45:58 +01:00
|
|
|
end
|
|
|
|
end
|