devise icon indicating copy to clipboard operation
devise copied to clipboard

Changing email to confirmed email should erase unconfirmed_email

Open ronalchn opened this issue 14 years ago • 4 comments

When changing email to itself, devise does nothing, because it thinks there is nothing to change. However, it is better to erase unconfirmed email so that it doesn't confuse the user, if for example confirmation instructions are sent.

ronalchn avatar Aug 05 '12 06:08 ronalchn

Sorry, I did not understand completely your report. In which screen are you changing the e-mail? Also, which devise version are you using? Thanks.

josevalim avatar Aug 05 '12 11:08 josevalim

There is no screen to change email in devise. But I hooked up another screen to change the email, using a devise function:

resource.update_with_password(params[resource_name]), with params[resource_name] = {:email => "email", :current_password => "password"}

If "email" is the same as current email, nothing happens. If "email" is different, it gets put into resource.unconfirmed_email

However, if resource.unconfirmed_email already has another email from a previous change which was never confirmed, then if you then update the email, but using what is currently in resource.email, then unconfirmed_email should be cleared.


Let resource.email = "email1" We change the email to email2, which causes resource.unconfirmed_email = "email2"

Now, we request another change, and change the email to email1.

However after this change, we still have resource = {:email => "email1", :unconfirmed_email => "email2"}.

Ideally, we should have resource = {:email => "email1", :unconfirmed_email => nil}, because there is no longer any email that needs to be confirmed.

ronalchn avatar Aug 05 '12 12:08 ronalchn

Perfect. Thanks for the detailed report, it makes sense, we will work on fixing it. :)

josevalim avatar Aug 05 '12 12:08 josevalim

@ronalchn I think this should be handled in your application and not Devise. Here is the thing, imagine another application contains a screen to edit the user, where you can change his name and also the e-mail. Now imagine that for both e-mail and name fields, we show the current valid name and e-mail values.

Now, if the user changes his e-mail, will set the unconfirmed e-mail, the screen will be reloaded, and we will still show the current e-mail on the field, because the unconfirmed one was not confirmed yet. Now, if the user changes his name, he will send the same current e-mail in the server, but he's still waiting for his unconfirmed e-mail and he doesn't want it to be cancelled as you proposed.

That said, this is coupled to the UI and we should not take an automatic measure. An application that has the e-mail field set to empty by default could afford to do the guessing as you proposed, but for some it would not. That said, I believe you should handle this scenario in your application.

josevalim avatar Oct 28 '12 16:10 josevalim