设计可重新确认 [英] devise reconfirmable

查看:49
本文介绍了设计可重新确认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的用户模型中使用设计选项 :reconfirmable,因此每当用户更改他的电子邮件时,他都需要通过电子邮件发送的链接进行确认.

I would like to use the devise option :reconfirmable in my user model, so whenever a user changes his email, he needs to confirm it with a link sent by email.

最大的问题是,电子邮件永远不会发送......

The big problem is, that the email gets never sent ...

我的设置与设计 2.1.2 是:

My setup is with devise 2.1.2 is:

用户模型:

attr_accessible: unconfirmed_email, ...

devise :invitable, :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :confirmable, :omniauthable

在初始化器 devise.rb 中:

in the initilizer devise.rb:

config.reconfirmable = true

在路线中:

devise_for :users

在表单中,模型字段 unconfirmed_email 设置正确.我通过控制台检查了这一点.

in the form the model field unconfirmed_email gets set properly. I checked this through the console.

第一封确认邮件,当用户在页面上注册时,会毫无问题地发送.

The first confirmation email, when a user registers on the page gets send out without problem.

我尝试通过将此代码添加到初始化程序目录以覆盖作为 after_update 挂钩触发的设计方法来调试问题:

I tried debugging the problem with adding this code to the initializers directory to overwrite the devise methode that gets triggered as a after_update hook:

module Devise::Models::Confirmable
  def send_confirmation_instructions
    debugger
  end
end

似乎从未调用过 send_confirmation_instructions,因为我从未接触过调试器.

it seems like send_confirmation_instructions is never called, since I never get to the debugger.

我是否需要以某种方式调用 reconfirmable,还是在将模型属性unconfirmed_email"设置为新电子邮件地址时自动触发?

Do I somehow need to call reconfirmable, or does it gets triggered automatically when setting the model attribute "unconfirmed_email" to a new email address?

感谢您的帮助,j.

推荐答案

好吧,尴尬了..

在深入研究 Devise 代码后,我发现您不需要设置用户模型的 unconfirmed_email 属性,而只需更改现有的电子邮件属性.属性 unconfirmed_email 仅用于 Devise 内部用于存储电子邮件地址,直到它被确认.

After diving into the Devise code, I figured out that you don't need to set the unconfirmed_email attribute of your user model, but just change the existing email attribute. The attribute unconfirmed_email is just used internally for Devise to store the email address until it's confirmed.

后来的 devise gem 版本在初始迁移中解释了这一点.这是 XXX_devise_create_users.rb 迁移中的可确认"部分(注意最后一行的注释):

Later version of devise gem explains this in initial migration. Here is "Confirmable" section (note the comment on the last line) from XXX_devise_create_users.rb migration:

  ## Confirmable
  t.string   :confirmation_token
  t.datetime :confirmed_at
  t.datetime :confirmation_sent_at
  t.string   :unconfirmed_email # Only if using reconfirmable

抱歉打扰了,但希望这可以帮助遇到同样问题的人......

Sorry for bothering, but hopefully this can help somebody having the same problem...

这篇关于设计可重新确认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆