我使用rails 3并设计3.0.3。我的设计视图和控制器大多是默认的。这是PasswordsController:
class PasswordsController < Devise::PasswordsController
layout "application_new"
def new
flash.clear
super
end
def create
self.resource = resource_class.send_reset_password_instructions(resource_params)
if successfully_sent?(resource)
respond_with({}, location: after_sending_reset_password_instructions_path_for(resource_name))
else
flash[:notice] = t("errors.no_user")
respond_with(resource)
end
end
def update
self.resource = resource_class.reset_password_by_token(resource_params)
if resource.errors.empty?
resource.unlock_access! if unlockable?(resource)
sign_in(resource_name, resource)
respond_with resource, location: after_resetting_password_path_for(resource)
else
flash[:notice] = resource.errors.full_messages
respond_with(resource)
end
end
end
这是编辑密码表单:
= form_for resource, as: resource_name, url: password_path(resource_name), html: { method: :put } do |f|
h2 = t('signup.password_recovery')
= f.hidden_field :reset_password_token
.form-group
= f.label :password, t("forms.new_password_label")
= f.password_field :password, required: true, class: "form-control"
.form-group
= f.label :password_confirmation, t("forms.password_confirmation_label")
= f.password_field :password_confirmation, required: true, class: "form-control"
= f.submit t('users.account.save'), class: 'btn btn-fill orange'
这是邮件程序模板:
= raw edit_password_url(@resource, reset_password_token: @resource.reset_password_token)
当我尝试重置用户密码时,它在开发中非常有效。这意味着,我收到一封带有重置链接的信件,其中包含参数中的重置密码令牌,并导致编辑密码页面,其中包含相应的表格和带有上述令牌的隐藏字段。
在制作中,我收到类似的字母,其中包含一个重置链接,其中包含参数中的重置密码令牌(它总是正确的令牌,我仔细检查过它);但是,当我打开编辑密码页面时,我会在隐藏的重置密码令牌字段中看到用户的电子邮件,而不是令牌本身。我不明白它是如何到达那里的。有什么建议吗?
P.S。我已经看过这个话题Rails 4 + Devise: Password Reset is always giving a "Token is invalid" error on the production server, but works fine locally.但事实并非如此,因为我在参数中得到了正确的令牌,问题是我得到了用户的电子邮件而不是我的令牌形式。
我希望看到的和我在开发中得到的东西:
<input id="user_reset_password_token" name="user[reset_password_token]" type="hidden" value="KyFVbsSUyAzsntDg4Dwf">
这就是我在制作中得到的:
<input id="user_reset_password_token" name="user[reset_password_token]" type="hidden" value="my_email@gmail.com">
答案 0 :(得分:0)
我发现问题的根源,实际上与Rails没有任何关系。 Safari只是通过我的电子邮件自动填充了隐藏的输入。由于这次讨论Safari autofills hidden "reset password token" input,我解决了这个问题。