Develop - create a user account with confirmation without sending an email?

I integrated development using facebook. Now, when I create a user account after the user logs in to my facebook account,

user = User.create(:email => data["email"], :password => Devise.friendly_token[0,20]) user.confirmed_at = DateTime.now user.save! 

although the account is verified, the confirmation email still starts. Any idea how I can turn off email?

+52
ruby-on-rails devise
Sep 19 2018-11-11T00:
source share
2 answers

The callback confirmation happens after creation, so it happens on line 1 of your example before you set confirmed_at manually.

According to the comments, the most correct task would be to use the method provided for this purpose, #skip_confirmation! . Configuring confirmed_at manually will work, but it bypasses the provided API, which should be avoided if possible.

So something like:

 user = User.new(user_attrs) user.skip_confirmation! user.save! 



Original answer:

If you pass confirmed_at along with your create arguments, the mail should not be sent, since checking whether or not the account has already been "verified" is to see if this date is set.

 User.create( :email => data['email'], :password => Devise.friendly_token[0,20], :confirmed_at => DateTime.now ) 

This or just use new instead of create to create your custom entry.

+121
Sep 19 '11 at 1:30
source share

If you just want to prevent sending emails, you can use #skip_confirmation_notification , for example:

 user = User.new(your, args) user.skip_confirmation_notification! user.save! 

See documentation

Skip the confirmation / re-confirmation notification message after_create / after_update. Unlike #skip_confirmation !, the entry still requires confirmation.

+8
Jul 02 '15 at 9:53 on
source share



All Articles