Get confirmation URL from user resource in Devise 3

So, Devise 3.1 now stores digest tokens in the database. I used the saved token to send subsequent emails to registered users, and if the user had not yet confirmed their email, I would add a link with the token:

Please confirm your account etc.
www.example.com?confirmation_token=<%= user.confirmation_token %>

The problem is that it is now user.confirmation_tokenencrypted, and I cannot use @tokenvar because this action does not come from Devise Controller.

Ultimately, I need a way to get the correct confirmation URL from a user’s resource without going through the development controller.

Is there any way to do this?

Edit:

Since there is no clear way to do this now, I opened the problem in Devise Github for further ideas:

https://github.com/plataformatec/devise/issues/2903

+4
source share
1 answer

It depends on when you send the email. If you do this at the same time as sending a regular confirmation message (so, in the same run loop as when creating the user), you should have access to the token by adding it to your user model:

def get_raw_confirmation_token
  return @raw_confirmation_token
end

If you send your subsequent email later, you will not be able to receive the existing confirmation token. It is stored in the database as a one-way hash for security purposes. However, you can create a new confirmation token and send it to your subsequent email. Add a new method to the user model as follows:

def generate_new_confirmation_token
  unless @raw_confirmation_token
    generate_confirmation_token!
  end
  return @raw_confirmation_token       
end

, . Devise , resend_confirmation_instructions , - , .

+3

Source: https://habr.com/ru/post/1529012/


All Articles