From d90a70e43c14f6f4bc7a93c3af1c54a15abaf497 Mon Sep 17 00:00:00 2001
From: Michael Barrett
Date: Thu, 10 Oct 2024 17:36:20 +0100
Subject: [PATCH] Moved 2fa resend button inside form and added countdown
---
ghost/admin/app/controllers/signin-verify.js | 22 ++++++++++++++++
ghost/admin/app/templates/signin-verify.hbs | 27 +++++++++++++-------
2 files changed, 40 insertions(+), 9 deletions(-)
diff --git a/ghost/admin/app/controllers/signin-verify.js b/ghost/admin/app/controllers/signin-verify.js
index f67b78388c..a307d35703 100644
--- a/ghost/admin/app/controllers/signin-verify.js
+++ b/ghost/admin/app/controllers/signin-verify.js
@@ -9,6 +9,8 @@ import {tracked} from '@glimmer/tracking';
const {Errors} = DS;
+const DEFAULT_RESEND_TOKEN_COUNTDOWN = 15;
+
// eslint-disable-next-line ghost/ember/alias-model-in-controller
class VerifyData {
@tracked token;
@@ -34,6 +36,25 @@ export default class SigninVerifyController extends Controller {
@tracked flowErrors = '';
@tracked verifyData = new VerifyData();
+ @tracked resendTokenCountdown = DEFAULT_RESEND_TOKEN_COUNTDOWN;
+ @tracked resendTokenCountdownStarted = false;
+
+ startResendTokenCountdown() {
+ this.resendTokenCountdown = DEFAULT_RESEND_TOKEN_COUNTDOWN;
+ this.resendTokenCountdownStarted = true;
+ this.resendTokenCountdownInterval = setInterval(() => {
+ if (this.resendTokenCountdown > 0) {
+ this.resendTokenCountdown = this.resendTokenCountdown - 1;
+ } else {
+ this.resetResendTokenCountdown();
+ }
+ }, 1000);
+ }
+
+ resetResendTokenCountdown() {
+ clearInterval(this.resendTokenCountdownInterval);
+ this.resendTokenCountdownStarted = false;
+ }
@action
resetData() {
@@ -74,6 +95,7 @@ export default class SigninVerifyController extends Controller {
// ember-ajax will try and parse the response as JSON if not explicitly set
dataType: 'text'
});
+ this.startResendTokenCountdown();
return true;
} catch (error) {
if (error && error.payload && error.payload.errors) {
diff --git a/ghost/admin/app/templates/signin-verify.hbs b/ghost/admin/app/templates/signin-verify.hbs
index 4e2ac364ca..b6dbc1cc76 100644
--- a/ghost/admin/app/templates/signin-verify.hbs
+++ b/ghost/admin/app/templates/signin-verify.hbs
@@ -13,7 +13,8 @@
-
+
+
+
+
+ {{#if this.resendTokenCountdownStarted}}
+ Resend again in {{this.resendTokenCountdown}}s
+ {{else}}
+ {{#if task.isRunning}}{{svg-jar "spinner" class="gh-spinner"}} Sending{{else}}Resend{{/if}}
+ {{/if}}
+
@@ -41,14 +58,6 @@
data-test-button="verify" />
-
-
{{if this.flowErrors this.flowErrors this.flowNotification}}