设计 - 创建用户帐户,确认不发送电子邮件? [英] Devise - create user account with confirmed without sending out an email?
问题描述
user = User.create :email => data [email],
:password => Devise.friendly_token [0,20])
user.confirmed_at = DateTime.now
user.save!
即使该帐户已被确认,确认电子邮件仍然被触发。任何想法如何可以关闭电子邮件?
确认回调在创建后发生,所以在您的示例的第1行发生之前,先设置 confirm_at
手动。
根据评论,最正确的做法是使用为此目的提供的方法, #skip_confirmation!
。手动设置 confirmation_at
将会起作用,但它会绕开提供的API,这是可能的时候应该避免的事情。
所以,如下所示:
user = User.new(user_attrs)
user.skip_confirmation!
user.save!
原始答案:
如果您通过 confirm_at
以及创建
参数,邮件不应该作为对帐户是否已经确认的测试,是查看该日期是否设定。
User.create(
:email => data ['email'],
:password => Devise.friendly_token [0,20],
:confirmation_at => DateTime 。$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ / / / / / / / / / / / / / / / / / / / / / / / / / code>而不是创建
来构建您的用户记录。
I integrated devise with facebook. Now when I create a user account after the user has logged in with his/her facebook account,
user = User.create(:email => data["email"],
:password => Devise.friendly_token[0,20])
user.confirmed_at = DateTime.now
user.save!
even though the account has been confirmed, an confirmation email is still fired. Any idea how I can turn the email firing off?
解决方案 The confirm callback happens after create, so it's happening on line 1 of your example, before you set confirmed_at
manually.
As per the comments, the most correct thing to do would be to use the method provided for this purpose, #skip_confirmation!
. Setting confirmed_at
manually will work, but it circumvents the provided API, which is something which should be avoided when possible.
So, something like:
user = User.new(user_attrs)
user.skip_confirmation!
user.save!
Original answer:
If you pass the confirmed_at
along with your create
arguments, the mail should not be sent, as the test of whether or not an account is already "confirmed" is to look at whether or not that date is set.
User.create(
:email => data['email'],
:password => Devise.friendly_token[0,20],
:confirmed_at => DateTime.now
)
That, or just use new
instead of create
to build your user record.
这篇关于设计 - 创建用户帐户,确认不发送电子邮件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!