我有以下代码,可以让用户在AJAX表单中请求重置密码:
有没有一种方法只回复第一次提交?
谢谢。
<%= form_for(resource, :as => resource_name, :url => password_path(resource_name), :html => { :method => :post },:remote =>'true') 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 %>
这会导致一个行为,即如果用户在服务器提供响应之前重复点击按钮或重复按下“enter”键,则将发送相应数量的密码重置电子邮件。
以下内容位于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
有没有一种方法只回复第一次提交?
谢谢。
if resource && (resource.reset_password_sent_at.nil? || Time.now > resource.reset_password_sent_at + 1.hour)
- Karens