Fix async

This commit is contained in:
2025-06-25 20:59:53 -07:00
parent f4133bc72d
commit b41cf1c3d7
2 changed files with 17 additions and 8 deletions
@@ -22,6 +22,10 @@ export class ForgotPasswordComponent {
}); });
} }
sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
onSubmit() { onSubmit() {
// Clear errors // Clear errors
this.errorMsgs = []; this.errorMsgs = [];
@@ -34,10 +38,11 @@ export class ForgotPasswordComponent {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}); });
this.http.post( "https://mistox.com/api/account/sendresetpassword", body, { headers, responseType: "text" } ).subscribe({ this.http.post( "https://mistox.com/api/account/sendresetpassword", body, { headers, responseType: "text" } ).subscribe({
next: (data) => { next: async (data) => {
if (data.trim() == "Success"){ if (data.trim() == "Success"){
this.errorMsgs = ["Reset password send"]; this.errorMsgs = ["Reset-password sent"];
setTimeout(() => { this.router.navigate([this.returnURL]); }, 3000); await this.sleep(3000);
this.router.navigate([this.returnURL]);
}else{ }else{
this.errorMsgs = [data]; this.errorMsgs = [data];
} }
@@ -27,8 +27,11 @@ export class ResetPasswordComponent {
}); });
} }
onSubmit() { sleep(ms: number) {
return new Promise(resolve => setTimeout(resolve, ms));
}
onSubmit() {
if (this.Password != this.PassworR){ if (this.Password != this.PassworR){
this.errorMsgs.push("Passwords must match"); this.errorMsgs.push("Passwords must match");
} }
@@ -36,7 +39,6 @@ export class ResetPasswordComponent {
this.errorMsgs.push("Password must be at least 6 Characters long"); this.errorMsgs.push("Password must be at least 6 Characters long");
} }
if (this.errorMsgs.length == 0){ if (this.errorMsgs.length == 0){
// Send to server and wait for response // Send to server and wait for response
this.errorMsgs.push("Waiting for login response from server"); this.errorMsgs.push("Waiting for login response from server");
const body = new HttpParams() const body = new HttpParams()
@@ -47,13 +49,15 @@ export class ResetPasswordComponent {
'Content-Type': 'application/x-www-form-urlencoded' 'Content-Type': 'application/x-www-form-urlencoded'
}); });
this.http.post<boolean>( "https://mistox.com/api/account/resetpassword", body, { headers } ).subscribe({ this.http.post<boolean>( "https://mistox.com/api/account/resetpassword", body, { headers } ).subscribe({
next: (data) => { next: async (data) => {
if (data == true){ if (data == true){
this.errorMsgs = ["Password reset successfully"]; this.errorMsgs = ["Password reset successfully"];
setTimeout(() => { this.router.navigate(["/account/login"]); }, 3000); await this.sleep(3000);
this.router.navigate(["/account/login"]);
}else{ }else{
this.errorMsgs = ["An error has ocurred"]; this.errorMsgs = ["An error has ocurred"];
setTimeout(() => { this.router.navigate(["/account/sendresetpassword"]); }, 3000); await this.sleep(3000);
this.router.navigate(["/account/sendresetpassword"]);
} }
}, },
error: err => { error: err => {