bitwarden-estensione-browser/apps/web/src/app/settings/two-factor-recovery.compone...

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-06-28 15:40:11 +02:00
import { Component } from "@angular/core";
2022-06-14 17:10:53 +02:00
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { TwoFactorProviderType } from "@bitwarden/common/enums/twoFactorProviderType";
import { TwoFactorRecoverResponse } from "@bitwarden/common/models/response/twoFactorRescoverResponse";
2018-06-28 15:40:11 +02:00
@Component({
selector: "app-two-factor-recovery",
templateUrl: "two-factor-recovery.component.html",
})
export class TwoFactorRecoveryComponent {
2018-07-18 23:10:26 +02:00
type = -1;
2018-06-28 15:40:11 +02:00
code: string;
authed: boolean;
twoFactorProviderType = TwoFactorProviderType;
2021-12-17 15:57:11 +01:00
2018-06-28 15:40:11 +02:00
constructor(private i18nService: I18nService) {}
2021-12-17 15:57:11 +01:00
2018-06-28 15:40:11 +02:00
auth(authResponse: any) {
this.authed = true;
this.processResponse(authResponse.response);
}
2021-12-17 15:57:11 +01:00
2018-06-28 15:40:11 +02:00
print() {
const w = window.open();
w.document.write(
'<div style="font-size: 18px; text-align: center;">' +
"<p>" +
this.i18nService.t("twoFactorRecoveryYourCode") +
":</p>" +
"<code style=\"font-family: Menlo, Monaco, Consolas, 'Courier New', monospace;\">" +
this.code +
"</code></div>" +
'<p style="text-align: center;">' +
new Date() +
"</p>"
);
w.onafterprint = () => w.close();
2018-06-28 15:40:11 +02:00
w.print();
}
2021-12-17 15:57:11 +01:00
2018-06-28 15:40:11 +02:00
private formatString(s: string) {
if (s == null) {
return null;
}
2021-12-17 15:57:11 +01:00
return s
2018-06-28 15:40:11 +02:00
.replace(/(.{4})/g, "$1 ")
2021-12-17 15:57:11 +01:00
.trim()
2018-06-28 15:40:11 +02:00
.toUpperCase();
2021-12-17 15:57:11 +01:00
}
2018-06-28 15:40:11 +02:00
private processResponse(response: TwoFactorRecoverResponse) {
this.code = this.formatString(response.code);
2021-12-17 15:57:11 +01:00
}
2018-06-28 15:40:11 +02:00
}