简体   繁体   中英

Devise reconfirmable not sending

Devise email confirmations for new accounts are sending just fine, but reconfirmation is not working for me. I have:

# config/initializers/devise.rb
config.reconfirmable = true

When I log in (confirmed or unconfirmed) and go to settings to change my email address, it saves the changes, but does not send the reconfirmation email.

I am using mongoid. I added the field :unconfirmed_email to the user model (together with all the others needed for confirmation. As I said confirmation works.). My user update action is very simple:

# registrations_controller
def update
  current_user.update_attributes(user_update_params)
  redirect_to current_user
end

My params include the :email field.

When I update the email, it is not copied to the unconfirmed_email field. That field remains nil for some reason.

Any ideas what I may be missing? I'm using all the most recent versions of Rails, Devise, Mongoid...

Update!

This is driving me nuts. I went ahead and reverted to Devise's own registration controller:

# registrations_controller.rb
class Users::RegistrationsController < Devise::RegistrationsController
end

and even suspended my own user edit document, so it's now using the basic Devise Edit form.

And STILL, it's sending confirmation just fine when signing up, but does not send reconfirmations.

I have this in devise.rb initializer:

config.reconfirmable = true
config.allow_unconfirmed_access_for = 2.days and confirmation_sent_at = Time.now

My database fields:

# user.rb
field :confirmation_token,                 type: String
field :confirmed_at,                       type: Time
field :confirmation_sent_at,               type: Time
field :unconfirmed_email,                  type: String

and I have these Devise settings:

devise :database_authenticatable, :registerable,
       :recoverable, :rememberable, :trackable,
       :confirmable,
       :omniauthable, :omniauth_providers => [:facebook]

The unconfirmed_email never changes, regardless of how often I update the email. The email gets updated actually, which is not logical if it was not confirmed.

What am I missing? How do I debug this?

I have just encountered the same problem.

To debug, I override the test methods of before_update and after_commit (or after_update for mongoid) like this:

# User.rb

def reconfirmation_required?
  result = super
  debugger
  result
end

def postpone_email_change?
  result = super
  debugger
  result
end

And when the execution is paused by the debugger statement, I printed out each term in the boolean expression of reconfirmation_required? and postpone_email_change? in console to see if they returned expected values.

In my case, I found that email_changed is always false regardless of email changed or not. 30 seconds later I found that email_changed is overridden in User.rb , and git blame shows that another developer did this hack months ago to skip sending confirmation letter when importing accounts.... Removing the hack makes reconfirmable works again.

Hope this piece of information helps. Good luck debugging!

Reference: Confirmable source code - https://github.com/plataformatec/devise/blob/master/lib/devise/models/confirmable.rb

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM