Delay and or resend Devise's confirmation email for manually created users

后端 未结 7 1957
予麋鹿
予麋鹿 2021-01-30 22:37

I\'m using Devise to allow user signup as-well-as using my own user admin to create users manually. When I create a user in the admin, Devise sends a confirmati

相关标签:
7条回答
  • 2021-01-30 22:40

    We do this in one of our apps. You can tell Devise NOT to automatically deliver the confirmation like this:

    @user.skip_confirmation!
    

    And then later, you can do

    Devise::Mailer.confirmation_instructions(@user).deliver
    

    For Rails 2.x you'd do something like:

    DeviseMailer.deliver_confirmation_instructions(@user)
    
    0 讨论(0)
  • 2021-01-30 22:40

    There is now the devise-async project:

    • https://github.com/mhfs/devise-async
    • https://github.com/plataformatec/devise/wiki/How-To:-Send-devise-emails-in-background-(Resque,-Sidekiq-and-Delayed::Job)
    0 讨论(0)
  • 2021-01-30 22:49

    I just spent some time looking into this, basically you just need to add this and setup delayed_job.

    def send_confirmation_instructions
      generate_confirmation_token! if self.confirmation_token.nil?
      ::Devise.mailer.delay.confirmation_instructions(self)
    end
    

    Add it in your user model as protected method to override the devise one in confirmable. Also, note the gem was just updated to add a new method to be overridden on create that sends the confirmation instructions.

    0 讨论(0)
  • 2021-01-30 22:59

    There's now an easier way (was added back in v2.2.4)

    Devise's confirmable module now includes the perfect skip_confirmation_notification! method which allows for a cleaner solution:

    @user = User.new params[:user]
    @user.skip_confirmation_notification! 
    @user.save
    
    # ... do stuff, then later...
    
    Devise::Mailer.confirmation_instructions(@user).deliver 
    
    0 讨论(0)
  • 2021-01-30 22:59

    Do you use delayed job ? It allows you to define single methods for delayed run.

    0 讨论(0)
  • 2021-01-30 23:05

    @user.skip_confirmation! confirms the user, so the user can log in without using the confirmation.

    This works for me in devise 3.5

    Stop devise to send confirmation email while creating user.

    @user.skip_confirmation_notification! 
    

    Send confirmation instructions later

    @user.send_confirmation_instructions
    
    0 讨论(0)
提交回复
热议问题