闭社主体 forked from https://github.com/tootsuite/mastodon
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.0 KiB

  1. # frozen_string_literal: true
  2. class User < ApplicationRecord
  3. include Settings::Extend
  4. devise :registerable, :recoverable,
  5. :rememberable, :trackable, :validatable, :confirmable,
  6. :two_factor_authenticatable, :two_factor_backupable,
  7. otp_secret_encryption_key: ENV['OTP_SECRET'],
  8. otp_number_of_backup_codes: 10
  9. belongs_to :account, inverse_of: :user, required: true
  10. accepts_nested_attributes_for :account
  11. validates :locale, inclusion: I18n.available_locales.map(&:to_s), unless: 'locale.nil?'
  12. validates :email, email: true
  13. scope :recent, -> { order('id desc') }
  14. scope :admins, -> { where(admin: true) }
  15. scope :confirmed, -> { where.not(confirmed_at: nil) }
  16. def send_devise_notification(notification, *args)
  17. devise_mailer.send(notification, self, *args).deliver_later
  18. end
  19. def setting_default_privacy
  20. settings.default_privacy || (account.locked? ? 'private' : 'public')
  21. end
  22. def setting_boost_modal
  23. settings.boost_modal
  24. end
  25. def setting_auto_play_gif
  26. settings.auto_play_gif
  27. end
  28. end