- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
解决方案
感谢这个gist在史蒂文·哈曼的帮助下,我成功了。devise_mail_helpers.rb
module Features
module MailHelpers
def last_email
ActionMailer::Base.deliveries[0]
end
# Can be used like:
# extract_token_from_email(:reset_password)
def extract_token_from_email(token_name)
mail_body = last_email.body.to_s
mail_body[/#{token_name.to_s}_token=([^"]+)/, 1]
end
end
end
我将文件 devise_mail_helpers.rb
添加到与功能规范相同的文件夹中,并编写了此规范。
require 'devise_mail_helpers.rb'
include Features
include MailHelpers
describe "PasswordResets" do
it "emails user when requesting password reset" do
user = FactoryGirl.create(:user)
visit root_url
find("#login_link").click
click_link "Forgot your password?"
fill_in "Email", :with => user.email
click_button "Send instructions"
current_path.should eq('/users/sign_in')
page.should have_content("You will receive an email with instructions about how to reset your password in a few minutes.")
last_email.to.should include(user.email)
token = extract_token_from_email(:reset_password) # Here I call the MailHelper form above
visit edit_password_url(reset_password_token: token)
fill_in "user_password", :with => "foobar"
fill_in "user_password_confirmation", :with => "foobar1"
find('.signup_firm').find(".submit").click
page.should have_content("Password confirmation doesn't match Password")
end
end
这会照顾规范,使其在浏览器中工作,请查看下面戴夫的答案。
原始问题
在我的 Rails 4 应用程序中,我已将 devise 升级到 3.1 并运行 rails s
,然后我得到了:
`raise_no_secret_key': Devise.secret_key was not set.
Please add the following to your Devise initializer: (RuntimeError)
config.secret_key = '--secret--'
我将 key 添加到设备初始值设定项中。
此后,当我尝试重置密码时,出现以下错误
Reset password token is invalid
电子邮件中发送的 token 似乎不正确。其他一切都正常。我登录和退出就像一把热刀切过黄油。
更新
现在我猜想它一定是与 reset_password_token
加密有关的东西,来自功能规范:
user = FactoryGirl.create(:user,
:reset_password_token => "something",
:reset_password_sent_at => 1.hour.ago)
visit edit_password_url(user, :reset_password_token =>
user.reset_password_token)
fill_in "user_password", :with => "foobar"
click_button "Change my password"
page.should have_content("Password confirmation doesn't match Password")
发生的错误是:
Failure/Error: page.should have_content
("Password confirmation doesn't match Password")
expected to find text "Password confirmation doesn't match Password" in
"Reset password token is invalid"
对我缺少的东西有什么想法吗?
最佳答案
您评论了my similar question不久前,我找到了一个可能对您也有帮助的答案。
升级到 Devise 3.1.0 在我有一段时间没有碰过的 View 中留下了一些“瑕疵”。根据this blog post ,您需要更改您的 Devise 邮件程序以使用 @token
而不是旧的@resource.confirmation_token
.
在 app/views/<user>/mailer/reset_password_instructions.html.erb
中找到此内容并将其更改为:
<p>Hello <%= @resource.email %>!</p>
<p>Someone has requested a link to change your password, and you can do this through the link below.</p>
<p><%= link_to 'Change my password', edit_password_url(@resource, :reset_password_token => @token) %></p>
<p>If you didn't request this, please ignore this email.</p>
<p>Your password won't change until you access the link above and create a new one.</p>
这应该可以解决您遇到的任何基于 token 的确认问题。这也可能解决任何解锁或确认 token 问题。
关于ruby-on-rails - 升级到 devise 3.1 => 获取重置密码 token 无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18661663/
我已将 Devise 设置为允许使用电子邮件或用户名登录。使用您的用户名,您可以拥有一个个性网址,如下所示:vanity.com/username。因此,我的用户模型具有 attr_accessibl
我有个类似的问题。我正在使用sendmail选项,并继续出现错误 “发送邮件需要使用SMTP发件人地址。设置邮件 smtp_envelope_from,return_path,发件人或地址。” 我已经
我在为我的用户表做种子时遇到问题。 (rails 3.2.6,jruby 1.6.7.2,devise 2.1.2) 这是一个非常通用的用户表,由“rails generate devise User
我为公司设计了一个设计。我做了一个表用户,希望我想存储用户信息密码等。当用户注册时,我希望它创建一个新用户和公司的关联。 我的公司模型:has_one:用户我的用户模型:Belongs_to: 公司
我目前正在从我们的应用程序中删除 IP 日志记录,我想知道使用 Devise 执行此操作的最佳方法是什么? 最佳答案 你的答案看起来不错,但如果你只想跟踪特定用户的 IP,一个(不那么冗长但可能更令人
我有一个包含 Devise (2.2.3) 和 Active Admin (0.5.1) 的应用程序,我先安装了 Devise,然后安装了 Active Admin。整个应用程序需要登录,所以在我的应
我有一个包含 Devise (2.2.3) 和 Active Admin (0.5.1) 的应用程序,我先安装了 Devise,然后安装了 Active Admin。整个应用程序需要登录,所以在我的应
我在 API 模式下使用 Rails,使用 Devise 和 Devise JWT(用于 API)和 ActiveAdmin。我一切正常,但我一直在构建 API Controller ,现在 Acti
在使用 Devise TestHelpers 的文档中,它声明使用诸如... @request.env["devise.mapping"] = Devise.mappings[:admin] 或者 @
许多程序员使用 devise 作为他们的身份验证解决方案,我想听听他们的建议: Devise 已经过测试,但我想知道是否有我自己要测试的东西(集成/单元/功能测试?),以根据我的知识进行标准设计集成(
我正在尝试通过 JSON 注册设备用户,但一直收到 ActiveModel::ForbiddenAttributesError class Api::V1::RegistrationsControll
我正在使用 Rails 4.0.2 和 Devise 3.2.2 来处理用户注册/身份验证。 我已经用谷歌搜索并在 stackoverflow 上搜索答案,但找不到可以回答我的问题的东西。 下面的代码
我正在使用 ruby 2.2.3 和 rails 4.2.5。我无法在我的项目上运行 rails generate devise:install。 Bundler 抛出错误。错误如下 rails
我正在使用设计和 devise-basecamper用于使用我的基于子域的 Web 应用程序进行身份验证。 我想允许 super 用户访问任何帐户(基本上是任何子域)。 我不确定我将如何实现这一点,以
我正在为我的应用程序实现设计邮件程序,我已完成以下步骤: 在模型中: class User "smtp.gmail.com", :port => 587, :domain =
我在 SO 上找到了类似的线程,但没有一个帮助我解决了这个问题。我的路线如下: devise_for :users do post '/users' => 'registrations#cre
编辑 2:看起来对我来说一个快速的临时修复是在我的 link_to_unless_current 和 current_page 方法中的 Controller 名称前面添加一个正斜杠“/”。例如 '
由于无法控制的原因,我无法在当前项目中使用RSpec进行测试。我正在尝试测试“设计重置密码”,但似乎无法提出有用的建议。 这是我到目前为止的内容: require 'test_helper' clas
我有一个问题,一开始看起来并不难,但实际上我无法解决。我正在尝试将 Refinery 用作应用程序的 CMS。我想将 Refinery 用户和其他类型的用户分开,称他们为 mktgeistusers,
我想自定义以下由devise提供的flash msg 在 devise.en.yml 文件中: devise: failure: unconfirmed: 'You have to
我是一名优秀的程序员,十分优秀!