设计 - 在不发送电子邮件的情况下创建用户帐户? [英] Devise - create user account with confirmed without sending out an email?

查看:17
本文介绍了设计 - 在不发送电子邮件的情况下创建用户帐户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将设计与 Facebook 集成.现在,当我在用户使用他/她的 Facebook 帐户登录后创建一个用户帐户时,

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?

推荐答案

confirm 回调发生在创建之后,所以它发生在你的例子的第 1 行,在你手动设置 confirmed_at 之前.

The confirm callback happens after create, so it's happening on line 1 of your example, before you set confirmed_at manually.

根据评论,最正确的做法是使用为此目的提供的方法,#skip_confirmation!.手动设置 confirmed_at 是可行的,但它绕过了提供的 API,这是应该尽可能避免的事情.

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.

所以,例如:

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

<小时>

原答案:


Original answer:

如果您将 confirmed_at 与您的 create 参数一起传递,则不应发送邮件,因为帐户是否已经确认"的测试是查看该日期是否已设置.

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
)

那个,或者只是使用 new 而不是 create 来建立你的用户记录.

That, or just use new instead of create to build your user record.

这篇关于设计 - 在不发送电子邮件的情况下创建用户帐户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆