Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Devise: Is it possible to NOT send a confirmation email in specific cases ? (even when confirmable is active)

Here is my situation, I use devise to allow users to create account on my site and manage their authentication. During the registration process I allow customers to change some options, leading to an actually different account being created but still based on the same core user resource. I would like to choose not to send a confirmation email for some of those account types. I don't care if the account do not get confirmed and user cannot log in, that's ok, no pb with that. How would I go about doing that ? Thanks, Alex

like image 610
Alex Avatar asked Jan 25 '11 06:01

Alex


3 Answers

Actually it's quite easy once I dig a little deeper. Just override one method in your User model (or whatever you are using):

    # Callback to overwrite if confirmation is required or not.
    def confirmation_required?
      !confirmed?
    end

Put your conditions and job's done !

Alex

like image 197
Alex Avatar answered Oct 31 '22 05:10

Alex


If you just want to skip sending the email but not doing confirmation, use:

# Skips sending the confirmation/reconfirmation notification email after_create/after_update. Unlike
# #skip_confirmation!, record still requires confirmation.
@user.skip_confirmation_notification!

If you don't want to call this in your model with a callback overwrite this method:

def send_confirmation_notification?
  false
end
like image 45
kmanzana Avatar answered Oct 31 '22 04:10

kmanzana


You can also simply add the following line of code in your controller before creating the new user:

@user.skip_confirmation!
like image 20
Joshua Harris Avatar answered Oct 31 '22 04:10

Joshua Harris