2018-07-13 22:24:53 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2021-10-15 00:59:43 +02:00
|
|
|
import { first } from "rxjs/operators";
|
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { ApiService } from "@bitwarden/common/abstractions/api.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";
|
2022-10-18 19:01:42 +02:00
|
|
|
import { VerifyDeleteRecoverRequest } from "@bitwarden/common/models/request/verify-delete-recover.request";
|
2018-07-13 22:24:53 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-verify-recover-delete",
|
|
|
|
templateUrl: "verify-recover-delete.component.html",
|
|
|
|
})
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2018-07-13 22:24:53 +02:00
|
|
|
export class VerifyRecoverDeleteComponent implements OnInit {
|
|
|
|
email: string;
|
|
|
|
formPromise: Promise<any>;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-13 22:24:53 +02:00
|
|
|
private userId: string;
|
|
|
|
private token: string;
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-13 22:24:53 +02:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private apiService: ApiService,
|
2021-12-07 20:41:45 +01:00
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private i18nService: I18nService,
|
2021-10-20 18:30:04 +02:00
|
|
|
private route: ActivatedRoute,
|
|
|
|
private logService: LogService
|
|
|
|
) {}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-13 22:24:53 +02:00
|
|
|
ngOnInit() {
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil, rxjs/no-async-subscribe
|
2021-10-15 00:59:43 +02:00
|
|
|
this.route.queryParams.pipe(first()).subscribe(async (qParams) => {
|
2018-07-13 22:24:53 +02:00
|
|
|
if (qParams.userId != null && qParams.token != null && qParams.email != null) {
|
|
|
|
this.userId = qParams.userId;
|
|
|
|
this.token = qParams.token;
|
|
|
|
this.email = qParams.email;
|
|
|
|
} else {
|
|
|
|
this.router.navigate(["/"]);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
|
2018-07-13 22:24:53 +02:00
|
|
|
async submit() {
|
|
|
|
try {
|
|
|
|
const request = new VerifyDeleteRecoverRequest(this.userId, this.token);
|
|
|
|
this.formPromise = this.apiService.postAccountRecoverDeleteToken(request);
|
|
|
|
await this.formPromise;
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"success",
|
|
|
|
this.i18nService.t("accountDeleted"),
|
2018-07-13 22:24:53 +02:00
|
|
|
this.i18nService.t("accountDeletedDesc")
|
|
|
|
);
|
|
|
|
this.router.navigate(["/"]);
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
2018-07-13 22:24:53 +02:00
|
|
|
}
|
2021-12-17 15:57:11 +01:00
|
|
|
}
|
2018-07-13 22:24:53 +02:00
|
|
|
}
|