devise icon indicating copy to clipboard operation
devise copied to clipboard

Confirmation token invalid shown if used twice misleading

Open ronalchn opened this issue 11 years ago • 5 comments

I just had a new user tell me that it wasn't letting him confirm his email.

When I checked, the email was already confirmed. Perhaps the page was loaded twice or something, and after the first use, the token is no longer valid.

I suggest that after confirming, the token is left in the database, so that the page can tell the user that it has already been confirmed.

I believe no extra DB columns are required, because the confirmed_at field is used to check whether an account is confirmed, and unconfirmed_email is used for whether any reconfirmation is required.

ronalchn avatar Jan 18 '15 23:01 ronalchn

I believe this has been fixed in latest Devise versions. Which Devise version are you using?

josevalim avatar Jan 19 '15 07:01 josevalim

devise (3.2.2)

ronalchn avatar Jan 19 '15 07:01 ronalchn

Ok, I was wrong, it seems we do not have this feature. Its addition is probably welcome!

josevalim avatar Jan 19 '15 07:01 josevalim

Just read some of the code. Would taking out the line setting the token to nil make it work? Once set to nil, the token cannot be looked up anymore. So you never check "pending_any_confirmation" again.

      def confirm!(args={})
        pending_any_confirmation do
          ...
          self.confirmation_token = nil # take this line out???
          ...
        end
      end

        def pending_any_confirmation
          if (!confirmed? || pending_reconfirmation?)
            yield
          else
            self.errors.add(:email, :already_confirmed)
            false
          end
        end

ronalchn avatar Jan 19 '15 08:01 ronalchn

That sounds like it! And a test case too. :)

josevalim avatar Jan 19 '15 08:01 josevalim