rails 设计重置密码令牌仅在生产中替换为用户的电子邮件

rails devise reset password token is replaced with user's email only in production

我使用 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)


当我尝试重置用户密码时,它在开发中运行良好。这意味着,我收到一封带有重置 link 的信件,其中包含参数中的重置密码令牌,并导致使用适当的形式编辑密码页面和隐藏字段,其中包含上述令牌。

在生产中,我收到类似的信件,其中包含重置 link 以及参数中的重置密码令牌(我仔细检查它总是正确的令牌);但是,当我打开编辑密码页面时,我在隐藏的重置密码令牌字段中看到了用户的电子邮件,而不是令牌本身。我不明白它是如何到达那里的。有什么建议吗?

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">

我找到了问题的根源,其实和Rails没有任何关系。 Safari 刚刚用我的电子邮件自动填充了隐藏的输入。由于这个讨论 Safari autofills hidden "reset password token" input.

,我解决了这个问题