2022-07-05 21:25:14 +02:00
|
|
|
import { Component, Input } from "@angular/core";
|
2022-07-26 14:48:11 +02:00
|
|
|
import { UntypedFormBuilder } from "@angular/forms";
|
2022-07-05 21:25:14 +02:00
|
|
|
import { Router } from "@angular/router";
|
|
|
|
|
|
|
|
import { RegisterComponent as BaseRegisterComponent } from "@bitwarden/angular/components/register.component";
|
|
|
|
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 { EnvironmentService } from "@bitwarden/common/abstractions/environment.service";
|
|
|
|
import { FormValidationErrorsService } from "@bitwarden/common/abstractions/formValidationErrors.service";
|
|
|
|
import { I18nService } from "@bitwarden/common/abstractions/i18n.service";
|
|
|
|
import { LogService } from "@bitwarden/common/abstractions/log.service";
|
|
|
|
import { PasswordGenerationService } from "@bitwarden/common/abstractions/passwordGeneration.service";
|
|
|
|
import { PlatformUtilsService } from "@bitwarden/common/abstractions/platformUtils.service";
|
|
|
|
import { PolicyService } from "@bitwarden/common/abstractions/policy.service";
|
|
|
|
import { StateService } from "@bitwarden/common/abstractions/state.service";
|
|
|
|
import { MasterPasswordPolicyOptions } from "@bitwarden/common/models/domain/masterPasswordPolicyOptions";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: "app-register-form",
|
|
|
|
templateUrl: "./register-form.component.html",
|
|
|
|
})
|
|
|
|
export class RegisterFormComponent extends BaseRegisterComponent {
|
|
|
|
@Input() queryParamEmail: string;
|
|
|
|
@Input() enforcedPolicyOptions: MasterPasswordPolicyOptions;
|
|
|
|
|
|
|
|
showErrorSummary = false;
|
|
|
|
|
|
|
|
constructor(
|
|
|
|
formValidationErrorService: FormValidationErrorsService,
|
2022-07-26 14:48:11 +02:00
|
|
|
formBuilder: UntypedFormBuilder,
|
2022-07-05 21:25:14 +02:00
|
|
|
authService: AuthService,
|
|
|
|
router: Router,
|
|
|
|
i18nService: I18nService,
|
|
|
|
cryptoService: CryptoService,
|
|
|
|
apiService: ApiService,
|
|
|
|
stateService: StateService,
|
|
|
|
platformUtilsService: PlatformUtilsService,
|
|
|
|
passwordGenerationService: PasswordGenerationService,
|
|
|
|
private policyService: PolicyService,
|
|
|
|
environmentService: EnvironmentService,
|
|
|
|
logService: LogService
|
|
|
|
) {
|
|
|
|
super(
|
|
|
|
formValidationErrorService,
|
|
|
|
formBuilder,
|
|
|
|
authService,
|
|
|
|
router,
|
|
|
|
i18nService,
|
|
|
|
cryptoService,
|
|
|
|
apiService,
|
|
|
|
stateService,
|
|
|
|
platformUtilsService,
|
|
|
|
passwordGenerationService,
|
|
|
|
environmentService,
|
|
|
|
logService
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
async ngOnInit() {
|
|
|
|
await super.ngOnInit();
|
|
|
|
|
|
|
|
if (this.queryParamEmail) {
|
|
|
|
this.formGroup.get("email")?.setValue(this.queryParamEmail);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async submit() {
|
|
|
|
if (
|
|
|
|
this.enforcedPolicyOptions != null &&
|
|
|
|
!this.policyService.evaluateMasterPassword(
|
|
|
|
this.masterPasswordScore,
|
|
|
|
this.formGroup.get("masterPassword")?.value,
|
|
|
|
this.enforcedPolicyOptions
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
this.platformUtilsService.showToast(
|
|
|
|
"error",
|
|
|
|
this.i18nService.t("errorOccurred"),
|
|
|
|
this.i18nService.t("masterPasswordPolicyRequirementsNotMet")
|
|
|
|
);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
await super.submit(false);
|
|
|
|
}
|
|
|
|
}
|