plataformatec/devise — Issue #1691: Confirmable with two-step sign-up process broken
Author: lukeredpath
Created: 2012-03-02 17:33:37+00:00
State: open

I'm having a problem using the Confirmable module with my user object.

Here are the basic business rules:

* Users do not register directly. They are created by an admin user using a backend interface. When they are created, they do not have an email or password, they have a separate unique ID and PIN only.

* Users sign in for the first time using their unique ID and PIN. I handle the authentication for this myself.

* When they first sign in, they are prompted to complete their registration by entering their name, email address and password.

* I want this email to be confirmable, but it's optional so I do not need to restrict their access if they are unconfirmed.

Following the Devise instructions for Confirmable, I've managed to achieve this in the following way:

* In my user model, I override `confirmation_required?`. My user model has a small state machine and they start off in a "new" state when created by an admin. When they complete the first sign in registration process, they move into a "registered" state. My method therefore looks like this:

```ruby
def confirmation_required?
return false unless registered?
super
end
```

* In the Devise config, I've set `allow_unconfirmed_access_for` to 100.years, so essentially forever.

Now here's the problem. When the user completes registration, Devise sets the `unconfirmed_email` to the new email address and then sets `email` to the previous email address but in this case, that is nil. The resulting `nil` email attribute means the user cannot sign in at all.

Is there an easy way I can override this behaviour without some horrible monkey patching?