Devise - 可确认不发送电子邮件

发布于 2024-11-12 12:03:34 字数 1187 浏览 4 评论 0原文

只是为了解决这个问题:我的应用程序中确实有电子邮件。

我刚刚添加 :confirmable 到我的用户模型中。

app/models/user.rb

devise :database_authenticatable, :registerable, :omniauthable,
   :recoverable, :rememberable, :trackable, :validatable, :confirmable

我确实在数据库中有可确认的部分:

db/schema.rb

create_table "users", :force => true do |t|
  ...
  t.string   "confirmation_token"
  t.datetime "confirmed_at"
  t.datetime "confirmation_sent_at"
end

由于omniauth,我已经覆盖了registrations_controller

app/controllers/registrations_controller.rb

def create
  super
  session[:omniauth] = nil unless @user.new_record?
end

所以我想弄清楚的是......我需要添加什么才能:

  1. 在用户注册后发送确认电子邮件< /p>

  2. 将用户重定向到自定义页面,说明电子邮件正在等待确认(如果他们尝试在未确认的情况下再次登录,他们将到达该页面)(在此处回答

  3. (应该自动处理?)当用户已验证将它们重定向到给定页面

更新:现在,当我创建用户时,它会自动确认的。这是为什么?

Just to get it out of the way: I do have emails working in my app.

I just added :confirmable to my user model.

app/models/user.rb

devise :database_authenticatable, :registerable, :omniauthable,
   :recoverable, :rememberable, :trackable, :validatable, :confirmable

I do have the confirmable part in the db:

db/schema.rb

create_table "users", :force => true do |t|
  ...
  t.string   "confirmation_token"
  t.datetime "confirmed_at"
  t.datetime "confirmation_sent_at"
end

Because of the omniauth I have overwritten registrations_controller:

app/controllers/registrations_controller.rb

def create
  super
  session[:omniauth] = nil unless @user.new_record?
end

So what I'm trying to figure out is… what do I need to add in order to:

  1. Get confirmation email sent after the user signs up

  2. Redirect the user to a custom page explaining the email is waiting to be confirmed (which they would get to if they tried signing in again without confirming) (answered here)

  3. (should be taken care of automatically?) When the user is verified redirect them to given page

Update: Right now, when I create a user it is automatically confirmed. Why is that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

黄昏下泛黄的笔记 2024-11-19 12:03:34

好吧,所以我没有意识到我的用户模型中有以下内容:

def send_confirmation_instructions
  # stops Devise from automatically sending a confirmation email
end

def confirmation_required?
  skip_confirmation!
end

评论它们会发送电子邮件。仍在尝试弄清楚如果用户未确认则登录后如何重定向。并试图弄清楚如何正确使用confirmation_required?

Ok, so I didn't realize I had the following in my user model:

def send_confirmation_instructions
  # stops Devise from automatically sending a confirmation email
end

def confirmation_required?
  skip_confirmation!
end

Commenting them out gets the email to be sent. Still trying to figure out how to redirect after sign in if the user isn't confirmed. And trying to figure out how to properly use confirmation_required?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文