Rails Devise failed attempts unlock customer handling

Viewed 17

I currently use devise with config.unlock_strategy = :email But I want to change it to none, so the template email is not sent, and I use my own logic. but my question is - how do I know the number of failed attempts is reached? Do I need to constantly check on my own - or is there some function I can implement that is automatically called upon maximum_attempts reached? Thanks

1 Answers

So, in order to custom handle the locked account strategy - I set the unlock_strategy to mail

config.unlock_strategy = :email

and override the send_unlock_instructions in the user object that uses devise.

#override DEVISE method to handle custom mailer
  def send_unlock_instructions
    raw, enc = Devise.token_generator.generate(self.class, :unlock_token)
    self.unlock_token = enc
    save(validate: false)

    if // my condition
      self.lock_access!(send_instructions: false)
      MailingHelper::unlock_instructions(self)
    else // perform devise notification
      send_devise_notification(:unlock_instructions, raw, {})
    end

    raw
  end

Related