1
0
mirror of https://github.com/bitwarden/browser.git synced 2024-10-09 05:57:40 +02:00
bitwarden-browser/src/app/settings/two-factor-recovery.component.ts

48 lines
1.5 KiB
TypeScript
Raw Normal View History

2018-06-28 15:40:11 +02:00
import { Component } from '@angular/core';
import { I18nService } from 'jslib-common/abstractions/i18n.service';
2018-06-28 15:40:11 +02:00
import { TwoFactorRecoverResponse } from 'jslib-common/models/response/twoFactorRescoverResponse';
2018-06-28 15:40:11 +02:00
import { TwoFactorProviderType } from 'jslib-common/enums/twoFactorProviderType';
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;
constructor(private i18nService: I18nService) { }
auth(authResponse: any) {
this.authed = true;
this.processResponse(authResponse.response);
}
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();
}
private formatString(s: string) {
if (s == null) {
return null;
}
return s.replace(/(.{4})/g, '$1 ').trim().toUpperCase();
}
private processResponse(response: TwoFactorRecoverResponse) {
this.code = this.formatString(response.code);
}
}