lundi 25 décembre 2017

Holding sending reset password emails until some indecator devise rails

I have a PasswordController inherit from Devise::PasswordsController, I made a create function that helps me to send user reset password notification email, its implementation:

  def create
    # I need to put some condition on the next line
    self.resource = resource_class.send_reset_password_instructions(resource_params)
    if successfully_sent?(resource)
      render :json => "Request successfully sent"
    else
      render :json => resource.errors, :status => 422
    end
  end

It works fine but if user clicked on reset password 5 times 5 emails will be sent to him (If a delay happened or something users never waits, they need fast resposne) and the last one will only work, So I want to disable sending email until this token expired or something, I searched about it but couldn't find anything, I thought about make a new attribute inside user table which will be a datetime to indicate when was the last time the email has been sent but i'm asking if there is a better way to make using devise.

Aucun commentaire:

Enregistrer un commentaire