devise reconfirmable
Asked Answered
T

1

25

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

My setup is with devise 2.1.2 is:

user model:

attr_accessible: unconfirmed_email, ...

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

in the initilizer devise.rb:

config.reconfirmable = true

in the routes:

devise_for :users

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.

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

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

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?

Thankfull for any help, j.

Treadle answered 8/7, 2012 at 22:15 Comment(3)
For reconfirmable to work you have to add a new column to your User table 't.string :unconfirmed_email # Only if using reconfirmable' Have you already done this ?Consanguineous
hi janders. thats all set up, I have the attribute in my user model and in attr_accessible ... I still havent solved this problem, so any help is very wellcome.Treadle
I am sorry, can't figure out what's wrongConsanguineous
T
47

OK, this is embarrassing..

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.

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

Treadle answered 11/7, 2012 at 14:8 Comment(2)
Thanks for this. Good to know that Devise "automagically" populates unconfirmed_email when I update email in the model. Don't forget to mark your answer as "Accepted" (yes, even though you answered it yourself!).Bolo
Yes... You thought right.. even if it was after 2 years.. it was helpfull to me. :)Underwood

© 2022 - 2024 — McMap. All rights reserved.