fix email 2fa validation (#9702)
This commit is contained in:
parent
8440759602
commit
75615902a3
|
@ -41,6 +41,7 @@ export abstract class TwoFactorBaseComponent {
|
||||||
this.authed = true;
|
this.authed = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** @deprecated used for formPromise flows.*/
|
||||||
protected async enable(enableFunction: () => Promise<void>) {
|
protected async enable(enableFunction: () => Promise<void>) {
|
||||||
try {
|
try {
|
||||||
await enableFunction();
|
await enableFunction();
|
||||||
|
@ -50,6 +51,10 @@ export abstract class TwoFactorBaseComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated used for formPromise flows.
|
||||||
|
* TODO: Remove this method when formPromises are removed from all flows.
|
||||||
|
* */
|
||||||
protected async disable(promise: Promise<unknown>) {
|
protected async disable(promise: Promise<unknown>) {
|
||||||
const confirmed = await this.dialogService.openSimpleDialog({
|
const confirmed = await this.dialogService.openSimpleDialog({
|
||||||
title: { key: "disable" },
|
title: { key: "disable" },
|
||||||
|
@ -78,6 +83,29 @@ export abstract class TwoFactorBaseComponent {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected async disableMethod() {
|
||||||
|
const confirmed = await this.dialogService.openSimpleDialog({
|
||||||
|
title: { key: "disable" },
|
||||||
|
content: { key: "twoStepDisableDesc" },
|
||||||
|
type: "warning",
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!confirmed) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const request = await this.buildRequestModel(TwoFactorProviderRequest);
|
||||||
|
request.type = this.type;
|
||||||
|
if (this.organizationId != null) {
|
||||||
|
await this.apiService.putTwoFactorOrganizationDisable(this.organizationId, request);
|
||||||
|
} else {
|
||||||
|
await this.apiService.putTwoFactorDisable(request);
|
||||||
|
}
|
||||||
|
this.enabled = false;
|
||||||
|
this.platformUtilsService.showToast("success", null, this.i18nService.t("twoStepDisabled"));
|
||||||
|
this.onUpdated.emit(false);
|
||||||
|
}
|
||||||
|
|
||||||
protected async buildRequestModel<T extends SecretVerificationRequest>(
|
protected async buildRequestModel<T extends SecretVerificationRequest>(
|
||||||
requestClass: new () => T,
|
requestClass: new () => T,
|
||||||
) {
|
) {
|
||||||
|
|
|
@ -27,7 +27,6 @@ export class TwoFactorEmailComponent extends TwoFactorBaseComponent {
|
||||||
@Output() onChangeStatus: EventEmitter<boolean> = new EventEmitter();
|
@Output() onChangeStatus: EventEmitter<boolean> = new EventEmitter();
|
||||||
type = TwoFactorProviderType.Email;
|
type = TwoFactorProviderType.Email;
|
||||||
sentEmail: string;
|
sentEmail: string;
|
||||||
formPromise: Promise<TwoFactorEmailResponse>;
|
|
||||||
emailPromise: Promise<unknown>;
|
emailPromise: Promise<unknown>;
|
||||||
override componentName = "app-two-factor-email";
|
override componentName = "app-two-factor-email";
|
||||||
formGroup = this.formBuilder.group({
|
formGroup = this.formBuilder.group({
|
||||||
|
@ -79,21 +78,22 @@ export class TwoFactorEmailComponent extends TwoFactorBaseComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
submit = async () => {
|
submit = async () => {
|
||||||
this.formGroup.markAllAsTouched();
|
|
||||||
if (this.formGroup.invalid) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
await this.disableEmail();
|
await this.disableEmail();
|
||||||
this.onChangeStatus.emit(false);
|
this.onChangeStatus.emit(false);
|
||||||
} else {
|
} else {
|
||||||
|
this.formGroup.markAllAsTouched();
|
||||||
|
if (this.formGroup.invalid) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await this.enable();
|
await this.enable();
|
||||||
this.onChangeStatus.emit(true);
|
this.onChangeStatus.emit(true);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private disableEmail() {
|
private disableEmail() {
|
||||||
return super.disable(this.formPromise);
|
return super.disableMethod();
|
||||||
}
|
}
|
||||||
|
|
||||||
sendEmail = async () => {
|
sendEmail = async () => {
|
||||||
|
@ -109,11 +109,9 @@ export class TwoFactorEmailComponent extends TwoFactorBaseComponent {
|
||||||
request.email = this.email;
|
request.email = this.email;
|
||||||
request.token = this.token;
|
request.token = this.token;
|
||||||
|
|
||||||
return super.enable(async () => {
|
const response = await this.apiService.putTwoFactorEmail(request);
|
||||||
this.formPromise = this.apiService.putTwoFactorEmail(request);
|
|
||||||
const response = await this.formPromise;
|
|
||||||
await this.processResponse(response);
|
await this.processResponse(response);
|
||||||
});
|
this.onUpdated.emit(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
onClose = () => {
|
onClose = () => {
|
||||||
|
|
Loading…
Reference in New Issue