【发布时间】:2018-04-05 10:16:25
【问题描述】:
我似乎找不到在哪里设计将用户标记为已确认?
有时我只想创建一个用户并自动确认用户。我知道有一个跳过确认功能,但很好奇它存储在数据库中的什么位置。
【问题讨论】:
-
confirmed_at列在users表中。
标签: ruby-on-rails devise
我似乎找不到在哪里设计将用户标记为已确认?
有时我只想创建一个用户并自动确认用户。我知道有一个跳过确认功能,但很好奇它存储在数据库中的什么位置。
【问题讨论】:
confirmed_at 列在users 表中。
标签: ruby-on-rails devise
Devise::Confirmable 使用列数据时间列confirmed_at。
# Confirmable tracks the following columns:
#
# * confirmation_token - A unique random token
# * confirmed_at - A timestamp when the user clicked the confirmation link
# * confirmation_sent_at - A timestamp when the confirmation_token was generated (not sent)
# * unconfirmed_email - An email address copied from the email attr. After confirmation
# this value is copied to the email attr then cleared
由于该列可以为空,因此实现很简单:
module Devise
module Models
module Confirmable
# ...
def confirmed?
!!confirmed_at
end
end
end
end
这很有效,因为在 Ruby 中,除了 nil 和 false 之外的所有内容都是 true。将confirmed_at 设置为任何日期时间(甚至是将来)都会确认记录。
module Devise
module Models
module Confirmable
# If you don't want confirmation to be sent on create, neither a code
# to be generated, call skip_confirmation!
def skip_confirmation!
self.confirmed_at = Time.now.utc
end
end
end
end
【讨论】: