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