From 152f5bc2a821c91e362bf0cf9bf919e3f4a32cf0 Mon Sep 17 00:00:00 2001 From: Vladyslav_Prykhodko Date: Thu, 26 May 2022 09:41:42 +0300 Subject: [PATCH] UI: Add action print backup code --- .../authentication-dialog.component.scss | 7 ++- .../backup-code-auth-dialog.component.html | 11 ++-- .../backup-code-auth-dialog.component.ts | 23 +++++++++ .../backup-code-print-template.raw | 50 +++++++++++++++++++ .../pages/security/security.component.html | 6 +-- .../assets/locale/locale.constant-en_US.json | 1 + 6 files changed, 90 insertions(+), 8 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-print-template.raw diff --git a/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/authentication-dialog.component.scss b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/authentication-dialog.component.scss index 0b27d00983..a9325b6468 100644 --- a/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/authentication-dialog.component.scss +++ b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/authentication-dialog.component.scss @@ -80,10 +80,10 @@ max-width: 500px; .container { max-width: 500px; - margin: 40px 0 24px; + margin: 40px 0 8px; .code { letter-spacing: 0.25px; - padding: 0 30px; + padding: 0 24px; margin-bottom: 16px; font-family: Roboto Mono, "Helvetica Neue", monospace; &.even { @@ -91,6 +91,9 @@ } } } + .action-buttons { + margin-bottom: 40px; + } } & ::ng-deep { diff --git a/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.html b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.html index 61701c9358..ab3ba1a797 100644 --- a/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.html +++ b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.html @@ -34,13 +34,18 @@ {{ code }} -

security.2fa.dialog.backup-code-warn

-
+
-
+

security.2fa.dialog.backup-code-warn

+
+ +
diff --git a/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.ts b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.ts index 70c2888ac5..5d3a26b13d 100644 --- a/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.ts +++ b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-auth-dialog.component.ts @@ -29,6 +29,9 @@ import { } from '@shared/models/two-factor-auth.models'; import { mergeMap, tap } from 'rxjs/operators'; import { ImportExportService } from '@home/components/import-export/import-export.service'; +import { deepClone } from '@core/utils'; + +import printTemplate from '!raw-loader!./backup-code-print-template.raw'; @Component({ selector: 'tb-backup-code-auth-dialog', @@ -62,4 +65,24 @@ export class BackupCodeAuthDialogComponent extends DialogComponent `
${code}
`).join(''); + const printPage = printTemplate.replace('${codesBlock}', codeTemplate); + const newWindow = window.open('', 'Print backup code'); + + newWindow.document.open(); + newWindow.document.write(printPage); + + setTimeout(() => { + newWindow.print(); + + newWindow.document.close(); + + setTimeout(() => { + newWindow.close(); + }, 10); + }, 0); + } } diff --git a/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-print-template.raw b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-print-template.raw new file mode 100644 index 0000000000..1ab7efc79f --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/security/authentication-dialog/backup-code-print-template.raw @@ -0,0 +1,50 @@ + + + + + Backup code + + + + + +
+
+

+ Backup codes +

+
+ ${codesBlock} +
+
+
+ + diff --git a/ui-ngx/src/app/modules/home/pages/security/security.component.html b/ui-ngx/src/app/modules/home/pages/security/security.component.html index 8daa2f63ae..4a43db2ce7 100644 --- a/ui-ngx/src/app/modules/home/pages/security/security.component.html +++ b/ui-ngx/src/app/modules/home/pages/security/security.component.html @@ -66,15 +66,15 @@ + [disabled]="(isLoading$ | async)" + *ngIf="twoFactorAuth.get(provider).value && provider !== twoFactorAuthProviderType.BACKUP_CODE && !activeSingleProvider"> security.2fa.main-2fa-method diff --git a/ui-ngx/src/assets/locale/locale.constant-en_US.json b/ui-ngx/src/assets/locale/locale.constant-en_US.json index 485960c2e2..07817603dd 100644 --- a/ui-ngx/src/assets/locale/locale.constant-en_US.json +++ b/ui-ngx/src/assets/locale/locale.constant-en_US.json @@ -2590,6 +2590,7 @@ "authenticate-with": "You can authenticate with:", "disable-2fa-provider-text": "Disabling {{name}} will make your account less secure", "disable-2fa-provider-title": "Are you sure you want to disable {{name}}?", + "get-new-code": "Get new code", "main-2fa-method": "Use as main two-factor authentication method", "dialog": { "activation-step-description-email": "The next time you login in, you will be prompted to enter the security code that will be sent to your email address.",