ruby-on-railsclearance

How to lock out user in clearance after X failed login attempt?


I'm using Rails 5 and clearance 1.16.0.

When user attempts loggin in for 4 times I would like to show them a mesaage saying they are now locked

 if user.failed_attempts > 3 
     user.lock = true
     flash[:error] = "You have been locked out, please contact admin to unlock account"
 end

I know I can have a guard to check if user is locked and prevent them from logging in but how do I determine that the user has failed logging in? and increment the failed attempts counter using clearance.

Thanks


Solution

  • It seems like the only way to do it is to override behavoir which I did not want to do.

    github.com/thoughtbot/clearance/issues/742