From 8d5b421e7db4a1bc403690de243a400750fc1d3c Mon Sep 17 00:00:00 2001 From: Adrian Gruntkowski Date: Mon, 27 Nov 2023 16:14:18 +0100 Subject: [PATCH] Fix waiting state under Chrome and Safari --- lib/plausible_web/components/two_factor.ex | 6 +++--- lib/plausible_web/templates/auth/user_settings.html.heex | 5 ++++- lib/plausible_web/templates/auth/verify_2fa.html.heex | 5 ++++- .../templates/auth/verify_2fa_recovery_code.html.heex | 4 ++-- lib/plausible_web/templates/auth/verify_2fa_setup.html.heex | 4 +++- 5 files changed, 16 insertions(+), 8 deletions(-) diff --git a/lib/plausible_web/components/two_factor.ex b/lib/plausible_web/components/two_factor.ex index f88fff608..65d6a2c77 100644 --- a/lib/plausible_web/components/two_factor.ex +++ b/lib/plausible_web/components/two_factor.ex @@ -4,6 +4,7 @@ defmodule PlausibleWeb.Components.TwoFactor do """ use Phoenix.Component + attr :id, :string, default: "verify-button" attr :form, :any, required: true attr :field, :any, required: true attr :class, :string, default: "" @@ -26,8 +27,7 @@ defmodule PlausibleWeb.Components.TwoFactor do ) %> @@ -47,7 +47,7 @@ defmodule PlausibleWeb.Components.TwoFactor do attr :state_param, :string, required: true attr :form_data, :any, required: true attr :form_target, :string, required: true - attr :onsubmit, :string, default: "" + attr :onsubmit, :string, default: nil attr :title, :string, required: true slot :icon, required: true diff --git a/lib/plausible_web/templates/auth/user_settings.html.heex b/lib/plausible_web/templates/auth/user_settings.html.heex index e57135b3b..06f1ee73a 100644 --- a/lib/plausible_web/templates/auth/user_settings.html.heex +++ b/lib/plausible_web/templates/auth/user_settings.html.heex @@ -458,6 +458,7 @@
<%= password_input(f, :password, + id: "disable_2fa_password", placeholder: "Enter password", "x-ref": "disable2FAPassword", class: @@ -472,6 +473,7 @@ state_param="regenerate2FAOpen" form_data={@conn.params} form_target={Routes.auth_path(@conn, :generate_2fa_recovery_codes)} + onsubmit="document.getElementById('generate-2fa-recovery-button').disabled = true" title="Generate New Recovery Codes?" > <:icon> @@ -480,8 +482,8 @@ <:buttons> <.button + id="generate-2fa-recovery-button" type="submit" - onclick="event.target.disabled = true" class="w-full sm:w-auto [&>span.label-enabled]:block [&>span.label-disabled]:hidden [&[disabled]>span.label-enabled]:hidden [&[disabled]>span.label-disabled]:block" > @@ -505,6 +507,7 @@
<%= password_input(f, :password, + id: "regenerate_2fa_password", placeholder: "Enter password", "x-ref": "regenerate2FAPassword", class: diff --git a/lib/plausible_web/templates/auth/verify_2fa.html.heex b/lib/plausible_web/templates/auth/verify_2fa.html.heex index 0ce7354ca..d50520b89 100644 --- a/lib/plausible_web/templates/auth/verify_2fa.html.heex +++ b/lib/plausible_web/templates/auth/verify_2fa.html.heex @@ -1,5 +1,8 @@
- <%= form_for @conn.params, Routes.auth_path(@conn, :verify_2fa), [class: "w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8"], fn f -> %> + <%= form_for @conn.params, Routes.auth_path(@conn, :verify_2fa), [ + class: "w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8", + onsubmit: "document.getElementById('verify-button').disabled = true" + ], fn f -> %>

Enter Your 2FA Code

diff --git a/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex b/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex index daf127f43..684cb62da 100644 --- a/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex +++ b/lib/plausible_web/templates/auth/verify_2fa_recovery_code.html.heex @@ -2,7 +2,8 @@ <%= form_for @conn.params, Routes.auth_path(@conn, :verify_2fa_recovery_code), [ - class: "w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8" + class: "w-full max-w-lg mx-auto bg-white dark:bg-gray-800 shadow-md rounded px-8 py-6 mb-4 mt-8", + onsubmit: "document.getElementById('use-code-button').disabled = true" ], fn f -> %>

Enter Recovery Code @@ -26,7 +27,6 @@ <.button id="use-code-button" type="submit" - onclick="event.target.disabled = true" class="w-full mt-2 [&>span.label-enabled]:block [&>span.label-disabled]:hidden [&[disabled]>span.label-enabled]:hidden [&[disabled]>span.label-disabled]:block" > diff --git a/lib/plausible_web/templates/auth/verify_2fa_setup.html.heex b/lib/plausible_web/templates/auth/verify_2fa_setup.html.heex index 244ede92c..7f05e8f2a 100644 --- a/lib/plausible_web/templates/auth/verify_2fa_setup.html.heex +++ b/lib/plausible_web/templates/auth/verify_2fa_setup.html.heex @@ -5,7 +5,9 @@

- <%= form_for @conn.params, Routes.auth_path(@conn, :verify_2fa_setup), [], fn f -> %> + <%= form_for @conn.params, Routes.auth_path(@conn, :verify_2fa_setup), [ + onsubmit: "document.getElementById('verify-button').disabled = true" + ], fn f -> %> Enter the code from your authenticator application before it expires or wait for a new one. <% end %>