Reputation: 351
I am trying to regenerate confirmation token for the users who have not confirmed their accounts yet. I want to resend confirmation email to the user say after few days.I am following this link to regenerate the new token for that user, and its generating it but still its not working.
https://github.com/plataformatec/devise/issues/2615.
and I am following these steps on my console locally.
@user = User.find_by_email("[email protected]")
token = Devise.token_generator.generate(@user.class, :confirmation_token)
then in token i am getting array such as
token = ["gfbgk4535843tbk","8545kjbng8hguhggre8gergerkgjebg8gergkerjgg9ergejgn"]
then i am just sending an email like this
Devise::Mailer.confirmation_instructinos(@user,token.last).deliver
then its delivering an email to that user, but when user clicks on confirm account it takes user to the site but when user tries to login its not working.
Upvotes: 1
Views: 5626
Reputation: 11421
You can resend confirmation email using Devise built in methods:
users = User.where('confirmation_token IS NOT NULL')
users.each do |user|
user.send_confirmation_instructions
end
send_confirmation_instructions method should generate a new token if token period expired. I've been using this approach a few times and it did what was expected.
Also you could try resend_confirmation_instructions,
# Resend confirmation token.
# Regenerates the token if the period is expired.
def resend_confirmation_instructions
pending_any_confirmation do
send_confirmation_instructions
end
end
comments above the method clearly states that token will be regenerated. I haven't tried this one yet.
Upvotes: 8