Fix async
This commit is contained in:
+8
-3
@@ -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];
|
||||
}
|
||||
|
||||
+9
-5
@@ -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<boolean>( "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 => {
|
||||
|
||||
Reference in New Issue
Block a user