Rails Devise Password Reset Email allowing multiple submissions
I have the following code that allows a user to request a password reset:
<%= form_for(resource, :as => resource_name, :url =>
password_path(resource_name), :html => { :method => :post }) do |f| %>
<%= devise_error_messages! %>
<div><%= f.label :email %><br />
<%= f.email_field :email %></div>
<div><%= f.submit "Send me reset password instructions" %></div>
<% end %>
This is allowing the behavior whereby if the user clicks the button
repeatedly, or presses "enter" repeatedly, before the server can provide a
response, a corresponding # of password reset emails are being sent.
The following is within devise/password_controller.rb
def create
self.resource =
resource_class.send_reset_password_instructions(resource_params)
if successfully_sent?(resource)
flash[:notice] = "You will receive an email with instructions about how
to reset your password in a few minutes."
respond_to do |format|
format.html #responds with default html file
format.js
end
else
respond_to do |format|
format.html #responds with default html file
format.js{ render :js => "$(\".deviseErrors\").html(\"<span
class='login-error'>Could not send reset instructions to that
address.</span>\");" } #this will be the javascript file we respond
with
end
end
end
Is there a way to only respond to the first submission?
Thanks
No comments:
Post a Comment