2022-10-28 20:54:55 +02:00
|
|
|
import { Component, OnInit } from "@angular/core";
|
|
|
|
import { FormBuilder, Validators } from "@angular/forms";
|
|
|
|
import { ActivatedRoute, Router } from "@angular/router";
|
2018-04-04 20:19:44 +02:00
|
|
|
|
2022-06-14 17:10:53 +02:00
|
|
|
import { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
2022-10-28 20:54:55 +02:00
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
2022-06-14 17:10:53 +02:00
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
2020-08-11 22:25:07 +02:00
|
|
|
|
2018-04-04 20:19:44 +02:00
|
|
|
@Component({
|
|
|
|
selector: "app-home",
|
2018-04-06 17:48:45 +02:00
|
|
|
templateUrl: "home.component.html",
|
2018-04-04 20:19:44 +02:00
|
|
|
})
|
2022-10-28 20:54:55 +02:00
|
|
|
export class HomeComponent implements OnInit {
|
|
|
|
loginInitiated = false;
|
|
|
|
|
|
|
|
formGroup = this.formBuilder.group({
|
|
|
|
email: ["", [Validators.required, Validators.email]],
|
|
|
|
});
|
|
|
|
|
2020-08-24 16:17:15 +02:00
|
|
|
constructor(
|
|
|
|
protected platformUtilsService: PlatformUtilsService,
|
2022-01-27 22:22:51 +01:00
|
|
|
private stateService: StateService,
|
2022-10-28 20:54:55 +02:00
|
|
|
private formBuilder: FormBuilder,
|
|
|
|
private router: Router,
|
|
|
|
private i18nService: I18nService,
|
|
|
|
private environmentService: EnvironmentService,
|
|
|
|
private route: ActivatedRoute
|
2020-08-24 16:17:15 +02:00
|
|
|
) {}
|
2022-10-28 20:54:55 +02:00
|
|
|
async ngOnInit(): Promise<void> {
|
|
|
|
const rememberedEmail = await this.stateService.getRememberedEmail();
|
|
|
|
if (rememberedEmail != null) {
|
|
|
|
this.formGroup.patchValue({ email: await this.stateService.getRememberedEmail() });
|
|
|
|
}
|
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-10-28 20:54:55 +02:00
|
|
|
submit() {
|
|
|
|
this.formGroup.markAllAsTouched();
|
|
|
|
if (this.formGroup.invalid) {
|
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
this.i18nService.t("errorOccured"),
|
|
|
|
this.i18nService.t("invalidEmail")
|
|
|
|
);
|
|
|
|
return;
|
2020-08-24 16:17:15 +02:00
|
|
|
}
|
2021-12-21 15:43:35 +01:00
|
|
|
|
2022-10-28 20:54:55 +02:00
|
|
|
this.stateService.setRememberedEmail(this.formGroup.value.email);
|
|
|
|
|
|
|
|
this.router.navigate(["login"], { queryParams: { email: this.formGroup.value.email } });
|
|
|
|
}
|
|
|
|
|
|
|
|
get selfHostedDomain() {
|
|
|
|
return this.environmentService.hasBaseUrl() ? this.environmentService.getWebVaultUrl() : null;
|
2021-12-21 15:43:35 +01:00
|
|
|
}
|
2020-08-11 22:25:07 +02:00
|
|
|
}
|