I need to write a log when somebody failes to log in to my app (to track bruteforce attempts). Also I decided to log successful authentications.
So I created a SessionsController < Devise::SessionsController and tried to override the sessions#create method like that: https://gist.github.com/3884693
The first part works perfectly, but when the auth failes rails throws some kind of an exception and never reaches the if statement. So I don’t know what to do.
This answer to a previous SO question – Devise: Registering log in attempts has the answer.
I tried out the suggestion, and was able to log both the successful & failed login attempts. Here is the relevant controller code:
The log has the following entries:
For a successful login
For a failed login