0
votes

I'm using devise in my rails app and users can sign up then immediately sign in without having to confirm their email address for 24 hours. I did this with the config.allow_unconfirmed_access_for option in the devise initializer. I was wondering what would be the best way to send a second confirmation email, 24 hours after they sign up if they haven't confirmed their email address and that would say something like:

"your account has been disabled because you haven't confirmed your email address in the last 24 hours. Please click here to reactivate your account"

I'm using sidekiq. Any answer or suggestion will be greatly appreciated, thanks in advance

1
You could use a cron job to send the email after 24 hours. railscasts.com/episodes/164-cron-in-rubyDoctor06
But I'm not just tying to send a second confirmation email, (I know how to do that) it would be a different email with a different message that still has the confirmation token in it.Badr Tazi
Why did someone down vote my question ? Why don't you rather tell me what's wrong with my questionBadr Tazi
thats how ppl are sometimes. Sometimes they like to see what you have tried.Doctor06

1 Answers

3
votes

Sidekiq lets you schedule jobs. At registration time, enqueue a job for 24 hours later that checks whether the user has been confirmed and if not, delivers the email.

First, you'll need the job, which simply accepts a user ID and send them mail:

class RegistrationReminder
  include Sidekiq::Worker

  def perform(user_id)
    user = User.find(user_id)
    return if user.confirmed_at # They already confirmed their email
    # Send them mail
  end
end

Then, customize your Devise controller with a sign_up method that enqueues the job.

rails generate devise:controllers users
class Users::SessionsController < Devise::SessionsController
  def sign_up(resource_name, user)
    RegistrationReminder.perform_in(24.hours, user.id)
    super # Finish signing the user in
  end
end
# config/routes.rb
devise_for :users, controllers: { sessions: "users/sessions" }