diff --git a/src/MistoxWebsite.Client/src/app/pages/account/forgotpassword/forgotpassword.component.ts b/src/MistoxWebsite.Client/src/app/pages/account/forgotpassword/forgotpassword.component.ts index 1b8ebf5..b1e7bf9 100644 --- a/src/MistoxWebsite.Client/src/app/pages/account/forgotpassword/forgotpassword.component.ts +++ b/src/MistoxWebsite.Client/src/app/pages/account/forgotpassword/forgotpassword.component.ts @@ -22,6 +22,10 @@ export class ForgotPasswordComponent { }); } + sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + onSubmit() { // Clear errors this.errorMsgs = []; @@ -34,10 +38,11 @@ export class ForgotPasswordComponent { 'Content-Type': 'application/x-www-form-urlencoded', }); this.http.post( "https://mistox.com/api/account/sendresetpassword", body, { headers, responseType: "text" } ).subscribe({ - next: (data) => { + next: async (data) => { if (data.trim() == "Success"){ - this.errorMsgs = ["Reset password send"]; - setTimeout(() => { this.router.navigate([this.returnURL]); }, 3000); + this.errorMsgs = ["Reset-password sent"]; + await this.sleep(3000); + this.router.navigate([this.returnURL]); }else{ this.errorMsgs = [data]; } diff --git a/src/MistoxWebsite.Client/src/app/pages/account/resetpassword/resetpassword.component.ts b/src/MistoxWebsite.Client/src/app/pages/account/resetpassword/resetpassword.component.ts index 2c39755..bd6a970 100644 --- a/src/MistoxWebsite.Client/src/app/pages/account/resetpassword/resetpassword.component.ts +++ b/src/MistoxWebsite.Client/src/app/pages/account/resetpassword/resetpassword.component.ts @@ -27,8 +27,11 @@ export class ResetPasswordComponent { }); } - onSubmit() { + sleep(ms: number) { + return new Promise(resolve => setTimeout(resolve, ms)); + } + onSubmit() { if (this.Password != this.PassworR){ this.errorMsgs.push("Passwords must match"); } @@ -36,7 +39,6 @@ export class ResetPasswordComponent { this.errorMsgs.push("Password must be at least 6 Characters long"); } if (this.errorMsgs.length == 0){ - // Send to server and wait for response this.errorMsgs.push("Waiting for login response from server"); const body = new HttpParams() @@ -47,13 +49,15 @@ export class ResetPasswordComponent { 'Content-Type': 'application/x-www-form-urlencoded' }); this.http.post( "https://mistox.com/api/account/resetpassword", body, { headers } ).subscribe({ - next: (data) => { + next: async (data) => { if (data == true){ this.errorMsgs = ["Password reset successfully"]; - setTimeout(() => { this.router.navigate(["/account/login"]); }, 3000); + await this.sleep(3000); + this.router.navigate(["/account/login"]); }else{ this.errorMsgs = ["An error has ocurred"]; - setTimeout(() => { this.router.navigate(["/account/sendresetpassword"]); }, 3000); + await this.sleep(3000); + this.router.navigate(["/account/sendresetpassword"]); } }, error: err => {