Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Display error messages instead of logging to console

Klaus Zanders320b5e50cc5f
diff --git a/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts b/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts
index 6d201ba281a..c39387b02fc 100644
--- a/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts
+++ b/frontend/src/stimulus/controllers/dynamic/two-factor-authentication.controller.ts
@@ -33,12 +33,13 @@ import * as WebAuthnJSON from '@github/webauthn-json/browser-ponyfill';
import QrCreator from 'qr-creator';
export default class TwoFactorAuthenticationController extends Controller {
- static targets = ['resendOptions', 'qrCodeElement', 'webauthnCredential'];
+ static targets = ['resendOptions', 'qrCodeElement', 'webauthnCredential', 'errorDisplay'];
- declare readonly resendOptionsTarget: HTMLElement;
- declare readonly webauthnCredentialTarget: HTMLInputElement;
+ declare readonly resendOptionsTarget:HTMLElement;
+ declare readonly webauthnCredentialTarget:HTMLInputElement;
+ declare readonly errorDisplayTarget:HTMLElement;
- async onVerifyDevice(event: SubmitEvent) {
+ async onVerifyDevice(event:SubmitEvent) {
const form = event.target as HTMLFormElement;
const data = form.dataset;
@@ -66,12 +67,12 @@ export default class TwoFactorAuthenticationController extends Controller {
return true;
} catch (error) {
- console.log(`Error registering device: ${error}`);
+ this.errorDisplayTarget.innerText = `Error registering device: ${error}`;
return false;
}
}
- async onCreateDevice(event: SubmitEvent) {
+ async onCreateDevice(event:SubmitEvent) {
const form = event.target as HTMLFormElement;
const data = form.dataset;
@@ -99,12 +100,12 @@ export default class TwoFactorAuthenticationController extends Controller {
return true;
} catch (error) {
- console.log(`Error registering device: ${error}`);
+ this.errorDisplayTarget.innerText = `Error registering device: ${error}`;
return false;
}
}
- qrCodeElementTargetConnected(target: HTMLElement) {
+ qrCodeElementTargetConnected(target:HTMLElement) {
QrCreator.render(
{
text: target.dataset.value as string,
@@ -118,12 +119,12 @@ export default class TwoFactorAuthenticationController extends Controller {
);
}
- print(evt: MouseEvent) {
+ print(evt:MouseEvent) {
evt.preventDefault();
window.print();
}
- toggleResendOptions(evt: MouseEvent) {
+ toggleResendOptions(evt:MouseEvent) {
evt.preventDefault();
this.resendOptionsTarget.hidden = !this.resendOptionsTarget.hidden;
}
diff --git a/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb b/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb
index 9d53a8024a7..56a92875a2c 100644
--- a/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb
+++ b/modules/two_factor_authentication/app/views/two_factor_authentication/authentication/request_otp.html.erb
@@ -33,6 +33,7 @@
<p><%= raw I18n.t('two_factor_authentication.devices.2fa_from_webauthn', device_name: identifier) %></p>
<hr class="form--separator">
<%= hidden_field_tag 'webauthn_credential', nil, "data-two-factor-authentication-target": "webauthnCredential" %>
+ <div class="form--field-error" data-two-factor-authentication-target="errorField"></div>
<% end %>
<% if remember_2fa_enabled? %>
<div class="form--field -wide-label">
diff --git a/modules/two_factor_authentication/app/views/two_factor_authentication/two_factor_devices/webauthn/_form.html.erb b/modules/two_factor_authentication/app/views/two_factor_authentication/two_factor_devices/webauthn/_form.html.erb
index d687433ce85..12d56b531cb 100644
--- a/modules/two_factor_authentication/app/views/two_factor_authentication/two_factor_devices/webauthn/_form.html.erb
+++ b/modules/two_factor_authentication/app/views/two_factor_authentication/two_factor_devices/webauthn/_form.html.erb
@@ -8,4 +8,7 @@
<%= t('two_factor_authentication.devices.text_identifier') %>
</div>
</div>
+ <p><%= t('two_factor_authentication.devices.webauthn.further_steps') %></p>
+ <div class="form--field-error" data-two-factor-authentication-target="errorDisplay"></div>
+
</fieldset>
diff --git a/modules/two_factor_authentication/config/locales/en.yml b/modules/two_factor_authentication/config/locales/en.yml
index 9b4971fc754..57c94b5db0d 100644
--- a/modules/two_factor_authentication/config/locales/en.yml
+++ b/modules/two_factor_authentication/config/locales/en.yml
@@ -123,6 +123,7 @@ en:
webauthn:
title: "WebAuthn"
description: Use Web Authentication to register a FIDO2 device (like a YubiKey) or the secure enclave of your mobile device as a second factor.
+ further_steps: After you have chosen a name, you can click the Continue button. Your browser will prompt you to present your WebAuthn device. When you have done so, you are done registering the device.
totp:
title: "Use your app-based authenticator"
provisioning_uri: "Provisioning URI"