首页 文章

rails devise reset密码令牌仅在 生产环境 中被用户的电子邮件替换

提问于
浏览
1

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

当我尝试重置用户密码时,它在开发中非常有效 . 这意味着,我收到一封带有重置链接的信件,其中包含参数中的重置密码令牌,并导致编辑密码页面,其中包含相应的表格和带有上述令牌的隐藏字段 .

在制作中,我得到类似的字母,其中包含一个带有重置密码令牌的重置链接参数(它总是正确的令牌,我仔细检查过它);但是,当我打开编辑密码页面时,我会在隐藏的重置密码令牌字段中看到用户的电子邮件,而不是令牌本身 . 我不明白它是如何实现的 . 有什么建议?

附:我已经看过这个主题Rails 4 + Devise: Password Reset is always giving a "Token is invalid" error on the production server, but works fine locally.它不是't the case, because I get right token in parameters, the problem is that somehow I get user'的电子邮件而不是我表单中的令牌 .

这就是我期望看到的以及我在开发中得到的东西:
<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">

1 回答

  • 0

    我找到了问题的根源,实际上与Rails没有任何关系 . Safari只是通过我的电子邮件自动填充了隐藏的输入 . 由于这次讨论,我解决了这个问题Safari autofills hidden "reset password token" input .

相关问题