2018-07-12 20:19:47 +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";
|
2022-10-18 19:01:42 +02:00
|
|
|
import { VerifyEmailRequest } from "@bitwarden/common/models/request/verify-email.request";
|
2023-06-06 22:34:53 +02:00
|
|
|
import { I18nService } from "@bitwarden/common/platform/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/platform/abstractions/log.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/platform/abstractions/platform-utils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/platform/abstractions/state.service";
|
2018-07-12 20:19:47 +02:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-verify-email-token",
|
|
|
|
templateUrl: "verify-email-token.component.html",
|
|
|
|
})
|
2022-08-26 18:09:28 +02:00
|
|
|
// eslint-disable-next-line rxjs-angular/prefer-takeuntil
|
2018-07-12 20:19:47 +02:00
|
|
|
export class VerifyEmailTokenComponent implements OnInit {
|
2021-12-14 17:10:26 +01:00
|
|
|
constructor(
|
|
|
|
private router: Router,
|
|
|
|
private platformUtilsService: PlatformUtilsService,
|
|
|
|
private i18nService: I18nService,
|
|
|
|
private route: ActivatedRoute,
|
|
|
|
private apiService: ApiService,
|
|
|
|
private logService: LogService,
|
|
|
|
private stateService: StateService,
|
|
|
|
) {}
|
2018-07-12 20:19:47 +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-12 20:19:47 +02:00
|
|
|
if (qParams.userId != null && qParams.token != null) {
|
|
|
|
try {
|
|
|
|
await this.apiService.postAccountVerifyEmailToken(
|
|
|
|
new VerifyEmailRequest(qParams.userId, qParams.token),
|
|
|
|
);
|
2021-12-14 17:10:26 +01:00
|
|
|
if (await this.stateService.getIsAuthenticated()) {
|
2018-07-12 20:19:47 +02:00
|
|
|
await this.apiService.refreshIdentityToken();
|
|
|
|
}
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("emailVerified"));
|
2024-02-02 21:13:37 +01:00
|
|
|
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
2018-07-12 20:19:47 +02:00
|
|
|
this.router.navigate(["/"]);
|
|
|
|
return;
|
2021-10-20 18:30:04 +02:00
|
|
|
} catch (e) {
|
|
|
|
this.logService.error(e);
|
|
|
|
}
|
2018-07-12 20:19:47 +02:00
|
|
|
}
|
2021-12-07 20:41:45 +01:00
|
|
|
this.platformUtilsService.showToast("error", null, this.i18nService.t("emailVerifiedFailed"));
|
2024-02-02 21:13:37 +01:00
|
|
|
// FIXME: Verify that this floating promise is intentional. If it is, add an explanatory comment and ensure there is proper error handling.
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-floating-promises
|
2018-07-12 20:19:47 +02:00
|
|
|
this.router.navigate(["/"]);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|