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
2 changes: 1 addition & 1 deletion app/javascript/packs/webauthn-setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function webauthn() {
};
if (location.href.indexOf('?error=') === -1 &&
!(navigator && navigator.credentials && navigator.credentials.create)) {
window.location.href = '/webauthn_setup?error=NotSupportedError';
window.location.href = '/login/two_factor/options';
}
const continueButton = document.getElementById('continue-button');
continueButton.addEventListener('click', () => {
Expand Down
17 changes: 17 additions & 0 deletions app/javascript/packs/webauthn-unhide.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
function unhideWebauthn() {
if (navigator && navigator.credentials && navigator.credentials.create) {
const elem = document.getElementById('select_webauthn');
if (elem) {
elem.classList.remove('hidden');
}
} else {
const checkboxes = document.querySelectorAll('input[name="two_factor_options_form[selection]"]');
for (let i = 0, len = checkboxes.length; i < len; i += 1) {
if (!checkboxes[i].classList.contains('hidden')) {
checkboxes[i].checked = true;
Comment thread
stevegsa marked this conversation as resolved.
Outdated
break;
}
}
}
}
document.addEventListener('DOMContentLoaded', unhideWebauthn);
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ def info
t("two_factor_authentication.#{option_mode}.#{method}_info")
end

def html_class
''
end

private

def option_mode
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@ class WebauthnSelectionPresenter < SelectionPresenter
def method
:webauthn
end

def html_class
'hidden'
end
end
end
18 changes: 11 additions & 7 deletions app/views/two_factor_authentication/options/index.html.slim
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,22 @@ p.mt-tiny.mb3 = @presenter.info
fieldset.m0.p0.border-none.
legend.mb2.serif.bold = @presenter.label
- @presenter.options.each_with_index do |option, index|
label.btn-border.col-12.mb2 for="two_factor_options_form_selection_#{option.type}"
.radio
= radio_button_tag('two_factor_options_form[selection]',
span id="select_#{option.type}" class="#{option.html_class}"
label.btn-border.col-12.mb2 for="two_factor_options_form_selection_#{option.type}"
.radio
= radio_button_tag('two_factor_options_form[selection]',
option.type,
index.zero?)
span.indicator.mt-tiny
span.blue.bold.fs-20p = option.label
.regular.gray-dark.fs-10p.mb-tiny = option.info
index.zero?,
class: option.html_class.to_s)
Comment thread
stevegsa marked this conversation as resolved.
Outdated
span.indicator.mt-tiny
span.blue.bold.fs-20p = option.label
.regular.gray-dark.fs-10p.mb-tiny = option.info

= f.button :submit, t('forms.buttons.continue')

br
- if @presenter.should_display_account_reset_or_cancel_link?
p = @presenter.account_reset_or_cancel_link
= render 'shared/cancel', link: destroy_user_session_path

== javascript_pack_tag 'webauthn-unhide'
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,10 @@
expect(subject.type).to eq 'webauthn'
end
end

describe '#html_class' do
it 'returns hidden' do
expect(subject.html_class).to eq 'hidden'
end
end
end