[fix] Add a fail state to registerAccount for failing validation (#3482)

This commit is contained in:
Addison Beck 2022-09-09 17:05:30 -04:00 committed by GitHub
parent 65641a38b7
commit 786558abb9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 13 additions and 10 deletions

View File

@ -104,7 +104,7 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
await this.buildRegisterRequest(email, masterPassword, name),
showToast
);
if (registerResponse.captchaRequired) {
if (!registerResponse.successful) {
return;
}
this.accountCreated = true;
@ -183,7 +183,7 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
};
}
private async validateRegistration(showToast: boolean) {
private async validateRegistration(showToast: boolean): Promise<{ isValid: boolean }> {
this.formGroup.markAllAsTouched();
this.showErrorSummary = true;
@ -193,19 +193,19 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
this.i18nService.t("errorOccurred"),
this.i18nService.t("acceptPoliciesRequired")
);
return;
return { isValid: false };
}
//web
if (this.formGroup.invalid && !showToast) {
return;
return { isValid: false };
}
//desktop, browser
if (this.formGroup.invalid && showToast) {
const errorText = this.getErrorToastMessage();
this.platformUtilsService.showToast("error", this.i18nService.t("errorOccurred"), errorText);
return;
return { isValid: false };
}
if (this.passwordStrengthResult != null && this.passwordStrengthResult.score < 3) {
@ -217,9 +217,10 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
"warning"
);
if (!result) {
return;
return { isValid: false };
}
}
return { isValid: true };
}
private async buildRegisterRequest(
@ -257,15 +258,17 @@ export class RegisterComponent extends CaptchaProtectedComponent implements OnIn
private async registerAccount(
request: RegisterRequest,
showToast: boolean
): Promise<{ captchaRequired: boolean }> {
await this.validateRegistration(showToast);
): Promise<{ successful: boolean }> {
if (!(await this.validateRegistration(showToast)).isValid) {
return { successful: false };
}
this.formPromise = this.apiService.postRegister(request);
try {
await this.formPromise;
return { captchaRequired: false };
return { successful: true };
} catch (e) {
if (this.handleCaptchaRequired(e)) {
return { captchaRequired: true };
return { successful: false };
} else {
throw e;
}