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

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

52 lines
1.9 KiB
TypeScript
Raw Normal View History

2018-07-13 21:36:27 +02:00
import { Component } from "@angular/core";
import { Router } from "@angular/router";
2022-06-14 17:10:53 +02:00
import { ApiService } from "@bitwarden/common/abstractions/api.service";
import { AuthService } from "@bitwarden/common/abstractions/auth.service";
import { CryptoService } from "@bitwarden/common/abstractions/crypto.service";
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
import { LogService } from "@bitwarden/common/abstractions/log.service";
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
import { TwoFactorRecoveryRequest } from "@bitwarden/common/models/request/twoFactorRecoveryRequest";
2018-07-13 21:36:27 +02:00
@Component({
selector: "app-recover-two-factor",
templateUrl: "recover-two-factor.component.html",
})
export class RecoverTwoFactorComponent {
email: string;
masterPassword: string;
recoveryCode: string;
formPromise: Promise<any>;
constructor(
private router: Router,
private apiService: ApiService,
2021-12-07 20:41:45 +01:00
private platformUtilsService: PlatformUtilsService,
private i18nService: I18nService,
private cryptoService: CryptoService,
private authService: AuthService,
private logService: LogService
) {}
2018-07-13 21:36:27 +02:00
async submit() {
try {
const request = new TwoFactorRecoveryRequest();
request.recoveryCode = this.recoveryCode.replace(/\s/g, "").toLowerCase();
2018-09-08 14:13:47 +02:00
request.email = this.email.trim().toLowerCase();
2018-08-14 21:14:04 +02:00
const key = await this.authService.makePreloginKey(this.masterPassword, request.email);
2018-07-13 21:36:27 +02:00
request.masterPasswordHash = await this.cryptoService.hashPassword(this.masterPassword, key);
this.formPromise = this.apiService.postTwoFactorRecover(request);
await this.formPromise;
2021-12-07 20:41:45 +01:00
this.platformUtilsService.showToast(
"success",
null,
this.i18nService.t("twoStepRecoverDisabled")
);
2018-07-13 21:36:27 +02:00
this.router.navigate(["/"]);
} catch (e) {
this.logService.error(e);
2018-07-13 21:36:27 +02:00
}
2021-12-17 15:57:11 +01:00
}
2018-07-13 21:36:27 +02:00
}