mirror of
https://github.com/yingziwu/mastodon.git
synced 2026-02-21 01:33:17 +00:00
Extract User::Confirmation concern (#35582)
This commit is contained in:
parent
15b72591d4
commit
6dc55a2f4e
4 changed files with 138 additions and 97 deletions
22
app/models/concerns/user/confirmation.rb
Normal file
22
app/models/concerns/user/confirmation.rb
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
module User::Confirmation
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
scope :confirmed, -> { where.not(confirmed_at: nil) }
|
||||
scope :unconfirmed, -> { where(confirmed_at: nil) }
|
||||
|
||||
def confirm
|
||||
wrap_email_confirmation { super }
|
||||
end
|
||||
end
|
||||
|
||||
def confirmed?
|
||||
confirmed_at.present?
|
||||
end
|
||||
|
||||
def unconfirmed?
|
||||
!confirmed?
|
||||
end
|
||||
end
|
||||
|
|
@ -58,6 +58,7 @@ class User < ApplicationRecord
|
|||
|
||||
include LanguagesHelper
|
||||
include Redisable
|
||||
include User::Confirmation
|
||||
include User::HasSettings
|
||||
include User::LdapAuthenticable
|
||||
include User::Omniauthable
|
||||
|
|
@ -118,8 +119,6 @@ class User < ApplicationRecord
|
|||
scope :recent, -> { order(id: :desc) }
|
||||
scope :pending, -> { where(approved: false) }
|
||||
scope :approved, -> { where(approved: true) }
|
||||
scope :confirmed, -> { where.not(confirmed_at: nil) }
|
||||
scope :unconfirmed, -> { where(confirmed_at: nil) }
|
||||
scope :enabled, -> { where(disabled: false) }
|
||||
scope :disabled, -> { where(disabled: true) }
|
||||
scope :active, -> { confirmed.signed_in_recently.account_not_suspended }
|
||||
|
|
@ -184,10 +183,6 @@ class User < ApplicationRecord
|
|||
current_sign_in_at.present? && current_sign_in_at >= ACTIVE_DURATION.ago
|
||||
end
|
||||
|
||||
def confirmed?
|
||||
confirmed_at.present?
|
||||
end
|
||||
|
||||
def invited?
|
||||
invite_id.present?
|
||||
end
|
||||
|
|
@ -212,12 +207,6 @@ class User < ApplicationRecord
|
|||
account_id
|
||||
end
|
||||
|
||||
def confirm
|
||||
wrap_email_confirmation do
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
# Mark current email as confirmed, bypassing Devise
|
||||
def mark_email_as_confirmed!
|
||||
wrap_email_confirmation do
|
||||
|
|
@ -264,10 +253,6 @@ class User < ApplicationRecord
|
|||
confirmed? && approved? && !disabled? && !account.unavailable? && !account.memorial?
|
||||
end
|
||||
|
||||
def unconfirmed?
|
||||
!confirmed?
|
||||
end
|
||||
|
||||
def unconfirmed_or_pending?
|
||||
unconfirmed? || pending?
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue