Skip to content

Commit 4f069af

Browse files
authored
[User] Disallow SMS enrollment for fresh users (#12371)
1 parent 3295c1e commit 4f069af

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

app/services/user_service/enroll_sms_auth.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,15 @@ def start_verification
1212
# doing this here to be safe.
1313
raise ArgumentError.new("phone number for user: #{@user.id} not in E.164 format") unless @user.phone_number =~ /\A\+[1-9]\d{1,14}\z/
1414

15+
disallow_fresh_users
16+
1517
TwilioVerificationService.new.send_verification_request(@user.phone_number)
1618
end
1719

1820
# Completing the phone number verification by checking that exchanging code works
1921
def complete_verification(verification_code)
22+
disallow_fresh_users
23+
2024
begin
2125
verified = TwilioVerificationService.new.check_verification_token(@user.phone_number, verification_code)
2226
rescue Twilio::REST::RestError
@@ -33,6 +37,8 @@ def enroll_sms_auth
3337
raise SMSEnrollmentError("user has no phone number") if @user.phone_number.blank?
3438
raise SMSEnrollmentError("user has not verified phone number") unless @user.phone_number_verified
3539

40+
disallow_fresh_users
41+
3642
@user.use_sms_auth = true
3743
@user.save!
3844
end
@@ -47,5 +53,11 @@ def disable_sms_auth
4753
class SMSEnrollmentError < StandardError
4854
end
4955

56+
def disallow_fresh_users
57+
return if @user.created_at < 1.day.ago
58+
59+
raise SMSEnrollmentError("Please wait at least 24 hours after creating your account before enrolling in SMS authentication.")
60+
end
61+
5062
end
5163
end

0 commit comments

Comments
 (0)