ruby-on-railsdevisepublic-activity

In Rails when using the Devise gem, how to log failed logins and lockups?


I use the Devise to handle the authentications in my app and have public_activity to record things and have a log. Now I need to add a record to the log when a failed login occurs and when a account gets locked. How can I do this?


Solution

  • You can use Warden's after_authentication hook as devise is built on warden. Put this in an config/initializers/devise_hooks.rb:

    Warden::Manager.after_authentication do |user, auth, opts|
      # do something with user
    end
    

    Read details in wardens wiki