36 changed files with 438 additions and 157 deletions
@ -0,0 +1,46 @@ |
|||
<!-- |
|||
|
|||
Copyright © 2016-2022 The Thingsboard Authors |
|||
|
|||
Licensed under the Apache License, Version 2.0 (the "License"); |
|||
you may not use this file except in compliance with the License. |
|||
You may obtain a copy of the License at |
|||
|
|||
http://www.apache.org/licenses/LICENSE-2.0 |
|||
|
|||
Unless required by applicable law or agreed to in writing, software |
|||
distributed under the License is distributed on an "AS IS" BASIS, |
|||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
|||
See the License for the specific language governing permissions and |
|||
limitations under the License. |
|||
|
|||
--> |
|||
<mat-toolbar fxLayout="row" color="primary"> |
|||
<h2 translate>security.2fa.dialog.get-backup-code-title</h2> |
|||
<span fxFlex></span> |
|||
<button mat-icon-button |
|||
(click)="closeDialog()" |
|||
type="button"> |
|||
<mat-icon class="material-icons">close</mat-icon> |
|||
</button> |
|||
</mat-toolbar> |
|||
<mat-progress-bar color="warn" mode="indeterminate" *ngIf="isLoading$ | async"> |
|||
</mat-progress-bar> |
|||
<div style="height: 4px;" *ngIf="!(isLoading$ | async)"></div> |
|||
<div mat-dialog-content tb-toast class="backup-code"> |
|||
<p class="mat-body-1 description" translate>security.2fa.dialog.backup-code-description</p> |
|||
<div class="container" fxLayout="row wrap"> |
|||
<div *ngFor="let code of backupCode?.codes; even as $even" fxFlex="50" class="code" [ngClass]="{'even': $even}"> |
|||
{{ code }} |
|||
</div> |
|||
</div> |
|||
<p class="mat-body-1 description" translate>security.2fa.dialog.backup-code-warn</p> |
|||
<div fxLayout="row" fxLayoutAlign="center start" fxLayoutGap="16px"> |
|||
<button type="button" mat-stroked-button color="primary" (click)="downloadFile()"> |
|||
{{ 'security.2fa.dialog.download-txt' | translate }} |
|||
</button> |
|||
<button type="button" mat-raised-button color="primary"> |
|||
{{ 'action.print' | translate }} |
|||
</button> |
|||
</div> |
|||
</div> |
|||
@ -0,0 +1,65 @@ |
|||
///
|
|||
/// Copyright © 2016-2022 The Thingsboard Authors
|
|||
///
|
|||
/// Licensed under the Apache License, Version 2.0 (the "License");
|
|||
/// you may not use this file except in compliance with the License.
|
|||
/// You may obtain a copy of the License at
|
|||
///
|
|||
/// http://www.apache.org/licenses/LICENSE-2.0
|
|||
///
|
|||
/// Unless required by applicable law or agreed to in writing, software
|
|||
/// distributed under the License is distributed on an "AS IS" BASIS,
|
|||
/// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|||
/// See the License for the specific language governing permissions and
|
|||
/// limitations under the License.
|
|||
///
|
|||
|
|||
import { Component } from '@angular/core'; |
|||
import { DialogComponent } from '@shared/components/dialog.component'; |
|||
import { Store } from '@ngrx/store'; |
|||
import { AppState } from '@core/core.state'; |
|||
import { Router } from '@angular/router'; |
|||
import { TwoFactorAuthenticationService } from '@core/http/two-factor-authentication.service'; |
|||
import { MatDialogRef } from '@angular/material/dialog'; |
|||
import { FormBuilder } from '@angular/forms'; |
|||
import { |
|||
AccountTwoFaSettings, |
|||
BackupCodeTwoFactorAuthAccountConfig, |
|||
TwoFactorAuthProviderType |
|||
} from '@shared/models/two-factor-auth.models'; |
|||
import { mergeMap, tap } from 'rxjs/operators'; |
|||
import { ImportExportService } from '@home/components/import-export/import-export.service'; |
|||
|
|||
@Component({ |
|||
selector: 'tb-backup-code-auth-dialog', |
|||
templateUrl: './backup-code-auth-dialog.component.html', |
|||
styleUrls: ['./authentication-dialog.component.scss'] |
|||
}) |
|||
export class BackupCodeAuthDialogComponent extends DialogComponent<BackupCodeAuthDialogComponent> { |
|||
|
|||
private config: AccountTwoFaSettings; |
|||
backupCode: BackupCodeTwoFactorAuthAccountConfig; |
|||
|
|||
constructor(protected store: Store<AppState>, |
|||
protected router: Router, |
|||
private twoFaService: TwoFactorAuthenticationService, |
|||
private importExportService: ImportExportService, |
|||
public dialogRef: MatDialogRef<BackupCodeAuthDialogComponent>, |
|||
public fb: FormBuilder) { |
|||
super(store, router, dialogRef); |
|||
this.twoFaService.generateTwoFaAccountConfig(TwoFactorAuthProviderType.BACKUP_CODE).pipe( |
|||
tap((data: BackupCodeTwoFactorAuthAccountConfig) => this.backupCode = data), |
|||
mergeMap(data => this.twoFaService.verifyAndSaveTwoFaAccountConfig(data, null, {ignoreLoading: true})) |
|||
).subscribe((config) => { |
|||
this.config = config; |
|||
}); |
|||
} |
|||
|
|||
closeDialog() { |
|||
this.dialogRef.close(this.config); |
|||
} |
|||
|
|||
downloadFile() { |
|||
this.importExportService.exportText(this.backupCode.codes, 'backup-codes'); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue