Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
84 changes: 5 additions & 79 deletions app/controllers/idv/by_mail/request_letter_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,38 +5,24 @@ module ByMail
class RequestLetterController < ApplicationController
include Idv::AvailabilityConcern
include IdvStepConcern
skip_before_action :confirm_no_pending_gpo_profile
include Idv::StepIndicatorConcern

before_action :confirm_mail_not_rate_limited
before_action :confirm_step_allowed
before_action :confirm_profile_not_too_old

def index
@applicant = idv_session.applicant
@presenter = RequestLetterPresenter.new(current_user, url_options)

Funnel::DocAuth::RegisterStep.new(current_user.id, current_sp&.issuer).
call(:usps_address, :view, true)
analytics.idv_request_letter_visited(
letter_already_sent: @presenter.resend_requested?,
)
analytics.idv_request_letter_visited
end

def create
clear_future_steps!
update_tracking
idv_session.address_verification_mechanism = :gpo

if resend_requested? && pii_locked?
redirect_to capture_password_url
elsif resend_requested?
resend_letter
flash[:success] = t('idv.messages.gpo.another_letter_on_the_way')
redirect_to idv_letter_enqueued_url
else
redirect_to idv_enter_password_url
end
redirect_to idv_enter_password_url
end

def gpo_mail_service
Expand All @@ -58,19 +44,14 @@ def self.step_info

private

def confirm_profile_not_too_old
redirect_to idv_path if gpo_mail_service.profile_too_old?
end

def update_tracking
Funnel::DocAuth::RegisterStep.new(current_user.id, current_sp&.issuer).
call(:usps_letter_sent, :update, true)

analytics.idv_gpo_address_letter_requested(
resend: resend_requested?,
first_letter_requested_at: first_letter_requested_at,
hours_since_first_letter:
hours_since_first_letter(first_letter_requested_at),
resend: false,
first_letter_requested_at: nil,
hours_since_first_letter: 0,
phone_step_attempts: RateLimiter.new(
user: current_user,
rate_limit_type: :proof_address,
Expand All @@ -82,65 +63,10 @@ def update_tracking
ProofingComponent.find_or_create_by(user: current_user).update(address_check: 'gpo_letter')
end

def resend_requested?
current_user.gpo_verification_pending_profile?
end

def first_letter_requested_at
current_user.gpo_verification_pending_profile&.gpo_verification_pending_at
end

def hours_since_first_letter(first_letter_requested_at)
first_letter_requested_at ?
(Time.zone.now - first_letter_requested_at).to_i.seconds.in_hours.to_i : 0
end

def confirm_mail_not_rate_limited
redirect_to idv_enter_password_url if gpo_mail_service.rate_limited?
end

def resend_letter
analytics.idv_gpo_address_letter_enqueued(
enqueued_at: Time.zone.now,
resend: true,
first_letter_requested_at: first_letter_requested_at,
hours_since_first_letter:
hours_since_first_letter(first_letter_requested_at),
phone_step_attempts: RateLimiter.new(
user: current_user,
rate_limit_type: :proof_address,
).attempts,
**ab_test_analytics_buckets,
)
confirmation_maker = confirmation_maker_perform
send_reminder
return unless FeatureManagement.reveal_gpo_code?
session[:last_gpo_confirmation_code] = confirmation_maker.otp
end

def confirmation_maker_perform
confirmation_maker = GpoConfirmationMaker.new(
pii: pii,
service_provider: current_sp,
profile: current_user.pending_profile,
)
confirmation_maker.perform
confirmation_maker
end

def pii
Pii::Cacher.new(current_user, user_session).
fetch(current_user.gpo_verification_pending_profile.id)
end

def send_reminder
current_user.send_email_to_all_addresses(:verify_by_mail_letter_requested)
end

def pii_locked?
!Pii::Cacher.new(current_user, user_session).exists_in_session?
end

def step_indicator_steps
if in_person_proofing?
Idv::Flows::InPersonFlow::STEP_INDICATOR_STEPS_GPO
Expand Down
127 changes: 127 additions & 0 deletions app/controllers/idv/by_mail/resend_letter_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,127 @@
# frozen_string_literal: true

module Idv
module ByMail
class ResendLetterController < ApplicationController
include Idv::AvailabilityConcern
include IdvSessionConcern
include Idv::StepIndicatorConcern

before_action :confirm_two_factor_authenticated
before_action :confirm_verification_needed
before_action :confirm_mail_not_rate_limited
before_action :confirm_profile_not_too_old

def new
analytics.idv_resend_letter_visited
end

def create
update_tracking

if pii_locked?
redirect_to capture_password_url
elsif resend_requested?
resend_letter
flash[:success] = t('idv.messages.gpo.another_letter_on_the_way')
redirect_to idv_letter_enqueued_url
end
end

def gpo_mail_service
@gpo_mail_service ||= Idv::GpoMail.new(current_user)
end

private

def confirm_verification_needed
return if current_user.gpo_verification_pending_profile?
redirect_to account_url
end

def confirm_profile_not_too_old
redirect_to idv_verify_by_mail_enter_code_path if gpo_mail_service.profile_too_old?
end

def confirm_mail_not_rate_limited
redirect_to idv_verify_by_mail_enter_code_path if gpo_mail_service.rate_limited?
end

def update_tracking
analytics.idv_gpo_address_letter_requested(
resend: true,
first_letter_requested_at: first_letter_requested_at,
hours_since_first_letter:
hours_since_first_letter(first_letter_requested_at),
phone_step_attempts: RateLimiter.new(
user: current_user,
rate_limit_type: :proof_address,
).attempts,
)
create_user_event(:gpo_mail_sent, current_user)
end

def resend_requested?
current_user.gpo_verification_pending_profile?
end

def first_letter_requested_at
current_user.gpo_verification_pending_profile&.gpo_verification_pending_at
end

def hours_since_first_letter(first_letter_requested_at)
first_letter_requested_at ?
(Time.zone.now - first_letter_requested_at).to_i.seconds.in_hours.to_i : 0
end

def resend_letter
analytics.idv_gpo_address_letter_enqueued(
enqueued_at: Time.zone.now,
resend: true,
first_letter_requested_at: first_letter_requested_at,
hours_since_first_letter:
hours_since_first_letter(first_letter_requested_at),
phone_step_attempts: RateLimiter.new(
user: current_user,
rate_limit_type: :proof_address,
).attempts,
)
confirmation_maker = confirmation_maker_perform
send_reminder
return unless FeatureManagement.reveal_gpo_code?
session[:last_gpo_confirmation_code] = confirmation_maker.otp
end

def confirmation_maker_perform
confirmation_maker = GpoConfirmationMaker.new(
pii: pii,
service_provider: current_sp,
profile: current_user.pending_profile,
)
confirmation_maker.perform
confirmation_maker
end

def pii
Pii::Cacher.new(current_user, user_session).
fetch(current_user.gpo_verification_pending_profile.id)
end

def send_reminder
current_user.send_email_to_all_addresses(:verify_by_mail_letter_requested)
end

def pii_locked?
!Pii::Cacher.new(current_user, user_session).exists_in_session?
end

def step_indicator_steps
if in_person_proofing?
Idv::Flows::InPersonFlow::STEP_INDICATOR_STEPS_GPO
else
StepIndicatorConcern::STEP_INDICATOR_STEPS_GPO
end
end
end
end
end
59 changes: 0 additions & 59 deletions app/presenters/idv/by_mail/request_letter_presenter.rb

This file was deleted.

14 changes: 11 additions & 3 deletions app/services/analytics_events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3157,16 +3157,24 @@ def idv_proofing_resolution_result_missing(
)
end

# @param [Boolean] letter_already_sent
# GPO "request letter" page visited
# @identity.idp.previous_event_name IdV: USPS address visited
def idv_request_letter_visited(
letter_already_sent:,
**extra
)
track_event(
'IdV: request letter visited',
letter_already_sent: letter_already_sent,
**extra,
)
end

# GPO "resend letter" page visited
# @identity.idp.previous_event_name IdV: request letter visited
def idv_resend_letter_visited(
**extra
)
track_event(
:idv_resend_letter_visited,
**extra,
)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
</p>

<% if @can_request_another_letter %>
<%= link_to t('idv.messages.gpo.resend'), idv_request_letter_path, class: 'display-block margin-top-4' %>
<%= link_to t('idv.messages.gpo.resend'), idv_resend_letter_path, class: 'display-block margin-top-4' %>
<% end %>

<hr class="margin-y-4" />
Expand Down
2 changes: 1 addition & 1 deletion app/views/idv/by_mail/enter_code/_enter_code.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</p>

<% if @can_request_another_letter %>
<%= link_to t('idv.messages.gpo.resend'), idv_request_letter_path, class: 'display-block margin-top-4' %>
<%= link_to t('idv.messages.gpo.resend'), idv_resend_letter_path, class: 'display-block margin-top-4' %>
<% end %>

<hr class="margin-y-4" />
Expand Down
Loading