-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6244 from CitizenLabDotCo/master
Release 2023-10-25
- Loading branch information
Showing
53 changed files
with
2,361 additions
and
4,916 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# frozen_string_literal: true | ||
|
||
class RequestConfirmationCodeJob < ApplicationJob | ||
self.priority = 30 # More important than default (50) | ||
|
||
attr_reader :user | ||
|
||
def run(user, new_email: nil) | ||
@user = user | ||
raise 'User confirmation is disabled.' if !AppConfiguration.instance.feature_activated?('user_confirmation') | ||
if !user.registered_with_email? && (!new_email || PhoneService.new.encoded_phone_or_email?(new_email) != :email) | ||
raise 'Confirmation is currently working for emails only.' | ||
end | ||
|
||
LogActivityJob.perform_later(user, 'requested_confirmation_code', user, Time.now.to_i, payload: { new_email: new_email }) | ||
if new_email | ||
user.new_email = new_email | ||
user.email_confirmation_code_reset_count = 0 | ||
end | ||
reset_user_confirmation_code user | ||
return if !user.valid? | ||
|
||
ActiveRecord::Base.transaction do | ||
user.save! | ||
deliver_confirmation_code! user | ||
schedule_code_expiration! user | ||
LogActivityJob.perform_later(user, 'received_confirmation_code', user, Time.now.to_i, payload: { new_email: new_email }) | ||
end | ||
end | ||
|
||
private | ||
|
||
def reset_user_confirmation_code(user) | ||
first_code = user.email_confirmation_code.nil? | ||
user.reset_confirmation_code | ||
user.increment_confirmation_code_reset_count if !first_code | ||
end | ||
|
||
def deliver_confirmation_code!(user) | ||
ConfirmationsMailer.with(user: user).send_confirmation_code.deliver_now | ||
user.update!(email_confirmation_code_sent_at: Time.zone.now) | ||
end | ||
|
||
def schedule_code_expiration!(user) | ||
ExpireConfirmationCodeOrDeleteJob.set( | ||
wait_until: user.email_confirmation_code_expiration_at | ||
).perform_later( | ||
user.id, | ||
user.email_confirmation_code | ||
) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,12 +248,14 @@ def expect_to_create_verified_user(user) | |
headers = { 'Authorization' => "Bearer #{token}" } | ||
post '/web_api/v1/user/resend_code', params: { new_email: '[email protected]' }, headers: headers | ||
expect(response).to have_http_status(:ok) | ||
expect(user.reload).to have_attributes({ email: '[email protected]' }) | ||
expect(user.reload).to have_attributes({ new_email: '[email protected]' }) | ||
expect(user.confirmation_required?).to be(true) | ||
|
||
post '/web_api/v1/user/confirm', params: { confirmation: { code: user.email_confirmation_code } }, headers: headers | ||
expect(response).to have_http_status(:ok) | ||
expect(user.reload.confirmation_required?).to be(false) | ||
expect(user).to have_attributes({ email: '[email protected]' }) | ||
expect(user.new_email).to be_nil | ||
end | ||
end | ||
|
||
|
Oops, something went wrong.