Rename and refactor User#confirm!
to User#mark_email_as_confirmed!
(#28735)
This commit is contained in:
parent
e621c1c44c
commit
98b5f85f10
7 changed files with 33 additions and 35 deletions
|
@ -190,37 +190,16 @@ class User < ApplicationRecord
|
|||
end
|
||||
|
||||
def confirm
|
||||
new_user = !confirmed?
|
||||
self.approved = true if grant_approval_on_confirmation?
|
||||
|
||||
super
|
||||
|
||||
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
|
||||
wrap_email_confirmation do
|
||||
super
|
||||
end
|
||||
end
|
||||
|
||||
def confirm!
|
||||
new_user = !confirmed?
|
||||
self.approved = true if grant_approval_on_confirmation?
|
||||
|
||||
skip_confirmation!
|
||||
save!
|
||||
|
||||
if new_user
|
||||
# Avoid extremely unlikely race condition when approving and confirming
|
||||
# the user at the same time
|
||||
reload unless approved?
|
||||
|
||||
prepare_new_user! if approved?
|
||||
# Mark current email as confirmed, bypassing Devise
|
||||
def mark_email_as_confirmed!
|
||||
wrap_email_confirmation do
|
||||
skip_confirmation!
|
||||
save!
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -435,6 +414,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.nil? && IpBlock.where(severity: :sign_up_requires_approval).where('ip >>= ?', sign_up_ip.to_s).exists?
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue