mirror of
https://github.com/mastodon/mastodon.git
synced 2024-11-21 21:57:19 +00:00
Extract User::Confirmation
concern
This commit is contained in:
parent
891cccb815
commit
77ebb32f6a
|
@ -15,38 +15,4 @@ module User::Confirmation
|
|||
def unconfirmed?
|
||||
!confirmed?
|
||||
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
|
||||
skip_confirmation!
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def wrap_email_confirmation
|
||||
new_user = !confirmed?
|
||||
self.approved = true if grant_approval_on_confirmation?
|
||||
|
||||
yield
|
||||
|
||||
if new_user
|
||||
# Handle race condition when approving and confirming user at the same time
|
||||
reload unless approved?
|
||||
|
||||
if approved?
|
||||
prepare_new_user!
|
||||
else
|
||||
notify_staff_about_pending_account!
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -188,6 +188,20 @@ 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
|
||||
skip_confirmation!
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
||||
def update_sign_in!(new_sign_in: false)
|
||||
old_current = current_sign_in_at
|
||||
new_current = Time.now.utc
|
||||
|
@ -401,6 +415,25 @@ class User < ApplicationRecord
|
|||
open_registrations? && !sign_up_from_ip_requires_approval? && !sign_up_email_requires_approval?
|
||||
end
|
||||
|
||||
def wrap_email_confirmation
|
||||
new_user = !confirmed?
|
||||
self.approved = true if grant_approval_on_confirmation?
|
||||
|
||||
yield
|
||||
|
||||
if new_user
|
||||
# Avoid extremely unlikely race condition when approving and confirming
|
||||
# the user at the same time
|
||||
reload unless approved?
|
||||
|
||||
if approved?
|
||||
prepare_new_user!
|
||||
else
|
||||
notify_staff_about_pending_account!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def sign_up_from_ip_requires_approval?
|
||||
sign_up_ip.present? && IpBlock.severity_sign_up_requires_approval.containing(sign_up_ip.to_s).exists?
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue