Skip to content
Merged
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
6 changes: 4 additions & 2 deletions app/components/block_link_component.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class BlockLinkComponent < BaseComponent
attr_reader :url, :action, :new_tab, :tag_options

alias_method :new_tab?, :new_tab

def initialize(url:, action: tag.method(:a), new_tab: false, **tag_options)
@action = action
@url = url
Expand All @@ -10,12 +12,12 @@ def initialize(url:, action: tag.method(:a), new_tab: false, **tag_options)

def css_class
classes = ['usa-link', 'block-link', *tag_options[:class]]
classes << 'usa-link--external' if new_tab
classes << 'usa-link--external' if new_tab?
classes
end

def target
'_blank' if new_tab
'_blank' if new_tab?
end

def wrapper(&block)
Expand Down
11 changes: 10 additions & 1 deletion app/components/troubleshooting_options_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,19 @@ class TroubleshootingOptionsComponent < BaseComponent

attr_reader :tag_options

def initialize(**tag_options)
def initialize(options: [], **tag_options)
@options_from_constructor = options
@tag_options = tag_options.dup
end

def options
@options_from_constructor.map(&method(:render)) + get_slot(:options)
end

def options?
options.present?
end

def render?
options?
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,7 @@ def render_show_after_invalid
end

def piv_cac_view_data
{
two_factor_authentication_method: 'piv_cac',
hide_fallback_question: service_provider_mfa_policy.piv_cac_required?,
}.merge(generic_data)
{ two_factor_authentication_method: 'piv_cac' }.merge(generic_data)
end

def piv_cac_verification_form
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ def header
t('two_factor_authentication.totp_header_text')
end

def fallback_question
t('two_factor_authentication.totp_fallback.question')
end

def cancel_link
if reauthn
account_path
else
sign_out_path
end
end

def redirect_location_step
:totp_verification
end
end
end
4 changes: 2 additions & 2 deletions app/presenters/two_factor_auth_code/backup_code_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ def cancel_link
end
end

def fallback_question
t('two_factor_authentication.backup_code_fallback.question')
def redirect_location_step
:backup_code_verification
end
end
end
26 changes: 24 additions & 2 deletions app/presenters/two_factor_auth_code/generic_delivery_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,30 @@ def link_path
login_two_factor_options_path
end

def fallback_links
raise NotImplementedError
def redirect_location_step; end

def troubleshooting_options
[
choose_another_method_troubleshooting_option,
learn_more_about_authentication_options_troubleshooting_option,
].select(&:present?)
end

def choose_another_method_troubleshooting_option
return if link_path.blank?
BlockLinkComponent.new(url: link_path).with_content(link_text)
end

def learn_more_about_authentication_options_troubleshooting_option
BlockLinkComponent.new(
url: help_center_redirect_path(
category: 'get-started',
article: 'authentication-options',
flow: :two_factor_authentication,
step: redirect_location_step,
),
new_tab: true,
).with_content(t('two_factor_authentication.learn_more'))
end

def remember_device_box_checked?
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/two_factor_auth_code/personal_key_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ module TwoFactorAuthCode
class PersonalKeyPresenter < TwoFactorAuthCode::GenericDeliveryPresenter
def initialize; end

def fallback_question
t('two_factor_authentication.personal_key_fallback.question')
def redirect_location_step
:personal_key_verification
end
end
end
44 changes: 15 additions & 29 deletions app/presenters/two_factor_auth_code/phone_delivery_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,38 +37,22 @@ def phone_call_text
t('two_factor_authentication.otp_delivery_preference.phone_call')
end

def fallback_question
t('two_factor_authentication.phone_fallback.question')
end

def troubleshooting_header
t('components.troubleshooting_options.default_heading')
end

def troubleshooting_options
[
troubleshoot_change_phone_or_method_option,
{
BlockLinkComponent.new(
url: help_center_redirect_path(
category: 'get-started',
article: 'authentication-options',
article_anchor: 'didn-t-receive-your-one-time-code',
flow: :two_factor_authentication,
step: :otp_confirmation,
),
text: t('two_factor_authentication.phone_verification.troubleshooting.code_not_received'),
new_tab: true,
},
{
url: help_center_redirect_path(
category: 'get-started',
article: 'authentication-options',
flow: :two_factor_authentication,
step: :otp_confirmation,
),
text: t('two_factor_authentication.learn_more'),
new_tab: true,
},
).with_content(
t('two_factor_authentication.phone_verification.troubleshooting.code_not_received'),
),
learn_more_about_authentication_options_troubleshooting_option,
]
end

Expand All @@ -81,19 +65,21 @@ def cancel_link
end
end

def redirect_location_step
:otp_confirmation
end

private

def troubleshoot_change_phone_or_method_option
if unconfirmed_phone
{
url: add_phone_path,
text: t('two_factor_authentication.phone_verification.troubleshooting.change_number'),
}
BlockLinkComponent.new(url: add_phone_path).with_content(
t('two_factor_authentication.phone_verification.troubleshooting.change_number'),
)
else
{
url: login_two_factor_options_path,
text: t('two_factor_authentication.login_options_link_text'),
}
BlockLinkComponent.new(url: login_two_factor_options_path).with_content(
t('two_factor_authentication.login_options_link_text'),
)
end
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,15 @@ def link_path
end
end

def troubleshooting_options
options = []
if service_provider_mfa_policy.allow_user_to_switch_method?
options << choose_another_method_troubleshooting_option
end
options << learn_more_about_authentication_options_troubleshooting_option
options
end

def cancel_link
if reauthn
account_path
Expand All @@ -54,17 +63,12 @@ def cancel_link
end
end

def piv_cac_service_link
login_two_factor_piv_cac_present_piv_cac_url
def redirect_location_step
:piv_cac_verification
end

def fallback_question
return if @hide_fallback_question
if service_provider_mfa_policy.allow_user_to_switch_method?
t('two_factor_authentication.piv_cac_fallback.question')
else
''
end
def piv_cac_service_link
login_two_factor_piv_cac_present_piv_cac_url
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ def link_path
end
end

def troubleshooting_options
options = [choose_another_method_troubleshooting_option].select(&:present?)
if platform_authenticator?
options << BlockLinkComponent.new(
url: help_center_redirect_path(
category: 'trouble-signing-in',
article: 'face-or-touch-unlock',
flow: :two_factor_authentication,
step: redirect_location_step,
),
new_tab: true,
).with_content(t('instructions.mfa.webauthn_platform.learn_more_help'))
end
options << learn_more_about_authentication_options_troubleshooting_option
options
end

def cancel_link
if reauthn
account_path
Expand All @@ -77,6 +94,10 @@ def cancel_link
end
end

def redirect_location_step
:webauthn_verification
end

def multiple_factors_enabled?
service_provider_mfa_policy.multiple_factors_enabled?
end
Expand Down
8 changes: 0 additions & 8 deletions app/views/shared/_fallback_links.html.erb

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<%= render TroubleshootingOptionsComponent.new(options: @presenter.troubleshooting_options) do |c| %>
<% c.with_header { t('components.troubleshooting_options.default_heading') } %>
<% end %>
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@
<%= f.submit t('forms.buttons.submit.default'), class: 'display-block margin-y-5' %>
<% end %>

<%= render 'shared/fallback_links', presenter: @presenter %>
<%= render 'two_factor_authentication/troubleshooting_options', presenter: @presenter %>
<%= render 'shared/cancel', link: sign_out_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,7 @@
).with_content(t('links.two_factor_authentication.send_another_code')) %>
<% end %>


<%= render(
'shared/troubleshooting_options',
heading: @presenter.troubleshooting_header,
options: @presenter.troubleshooting_options,
) %>
<%= render 'two_factor_authentication/troubleshooting_options', presenter: @presenter %>

<% if MfaPolicy.new(current_user).two_factor_enabled? %>
<%= render 'shared/cancel', link: @presenter.cancel_link %>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@
<%= f.submit t('forms.buttons.submit.default'), class: 'display-block margin-y-5' %>
<% end %>

<%= render 'shared/fallback_links', presenter: @presenter %>
<%= render 'two_factor_authentication/troubleshooting_options', presenter: @presenter %>
<%= render 'shared/cancel', link: sign_out_path %>
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,6 @@
wide: true,
).with_content(@presenter.piv_cac_capture_text) %>
</div>
<%= render 'shared/fallback_links', presenter: @presenter %>

<%= render 'two_factor_authentication/troubleshooting_options', presenter: @presenter %>
<%= render 'shared/cancel', link: @presenter.cancel_link %>
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,5 @@
) %>
</p>

<%= render 'shared/fallback_links', presenter: @presenter %>
<%= render 'two_factor_authentication/troubleshooting_options', presenter: @presenter %>
<%= render 'shared/cancel', link: @presenter.cancel_link %>
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,6 @@
},
) %>

<%= render TroubleshootingOptionsComponent.new do |c| %>
<% c.with_header { t('components.troubleshooting_options.default_heading') } %>
<% if @presenter.link_path.present? %>
<% c.with_option(url: @presenter.link_path).with_content(@presenter.link_text) %>
<% end %>
<% if @presenter.platform_authenticator? %>
<% c.with_option(
url: help_center_redirect_path(
category: 'trouble-signing-in',
article: 'face-or-touch-unlock',
flow: :two_factor_authentication,
step: :webauthn_verification,
),
new_tab: true,
).with_content(t('instructions.mfa.webauthn_platform.learn_more_help')) %>
<% end %>
<% c.with_option(
url: help_center_redirect_path(
category: 'get-started',
article: 'authentication-options',
flow: :two_factor_authentication,
step: :webauthn_verification,
),
new_tab: true,
).with_content(t('two_factor_authentication.learn_more')) %>
<% end %>
<%= render 'two_factor_authentication/troubleshooting_options', presenter: @presenter %>
<% end %>
<%= render 'shared/cancel', link: @presenter.cancel_link %>
Loading