bitwarden-estensione-browser/libs/angular/src/components/hint.component.ts

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

56 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-04-04 15:47:43 +02:00
import { Router } from "@angular/router";
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";
import { PasswordHintRequest } from "@bitwarden/common/models/request/password-hint.request";
2018-04-04 15:47:43 +02:00
export class HintComponent {
2022-02-22 15:39:11 +01:00
email = "";
2018-04-04 15:47:43 +02:00
formPromise: Promise<any>;
protected successRoute = "login";
2018-10-15 19:02:31 +02:00
protected onSuccessfulSubmit: () => void;
2018-04-04 15:47:43 +02:00
constructor(
protected router: Router,
protected i18nService: I18nService,
protected apiService: ApiService,
protected platformUtilsService: PlatformUtilsService,
private logService: LogService
) {}
2018-04-04 15:47:43 +02:00
async submit() {
if (this.email == null || this.email === "") {
2018-10-03 05:09:19 +02:00
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
2018-04-04 15:47:43 +02:00
this.i18nService.t("emailRequired")
);
return;
}
if (this.email.indexOf("@") === -1) {
2018-10-03 05:09:19 +02:00
this.platformUtilsService.showToast(
"error",
this.i18nService.t("errorOccurred"),
2018-04-04 15:47:43 +02:00
this.i18nService.t("invalidEmail")
);
return;
}
try {
this.formPromise = this.apiService.postPasswordHint(new PasswordHintRequest(this.email));
await this.formPromise;
2018-10-03 05:09:19 +02:00
this.platformUtilsService.showToast("success", null, this.i18nService.t("masterPassSent"));
2018-10-15 19:02:31 +02:00
if (this.onSuccessfulSubmit != null) {
this.onSuccessfulSubmit();
} else if (this.router != null) {
this.router.navigate([this.successRoute]);
}
} catch (e) {
this.logService.error(e);
2018-04-04 15:47:43 +02:00
}
2021-12-16 13:36:21 +01:00
}
2018-04-04 15:47:43 +02:00
}