设计在哪里存储用户确认标志?

时间:2017-10-24 14:43:32

标签: ruby-on-rails devise

我似乎无法找到设计标记用户的确认与否?

有时我只想创建一个用户并自动确认用户。我知道有一个跳过确认功能,但很奇怪它存储在数据库中。

1 个答案:

答案 0 :(得分:1)

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之外的所有内容都是正确的。将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

来自the Devise source