Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

devise reconfirmable

Tags:

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.

like image 356
user1311103 Avatar asked Jul 08 '12 22:07

user1311103


People also ask

What is confirmable devise?

module Devise. module Models. # Confirmable is responsible to verify if an account is already confirmed to. # sign in, and to send emails with confirmation instructions.

What is devise warden?

Warden is a ruby gem that does the actual authentication through an array of strategies; when the first strategy fails to authenticate the user, it uses the next and so forth. Devise adds several strategies to Warden, according to your User Model configuration (if it is rememberable, database_authenticatable, etc.)


1 Answers

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

like image 132
user1311103 Avatar answered Oct 30 '22 05:10

user1311103