diff --git a/src/app/forgot-password/forgot-password.page.html b/src/app/forgot-password/forgot-password.page.html index 7eb0fda..cf2f507 100644 --- a/src/app/forgot-password/forgot-password.page.html +++ b/src/app/forgot-password/forgot-password.page.html @@ -1,18 +1,52 @@ -
-
- Reset Password -
-

- Please enter to your email -

- -
- -
- - - - -
+
+
+ Reset Password +
+

+ Please enter to your email +

+ +
+ +
+ + + + +
+ +
+
+ Reset Password +
+

+ Please verify the OTP +

+ +
+ +
+ + + + +
+ +
+
+ Reset Password +
+

+ Please enter your new Password +

+ +
+ +
+ + + + +
diff --git a/src/app/forgot-password/forgot-password.page.ts b/src/app/forgot-password/forgot-password.page.ts index 9709e3a..6893f0e 100644 --- a/src/app/forgot-password/forgot-password.page.ts +++ b/src/app/forgot-password/forgot-password.page.ts @@ -1,6 +1,7 @@ import { Component, OnInit } from '@angular/core'; import { AuthService } from '../services/auth.service'; import { ToastService } from '../services/toast.service'; +import { Router } from '@angular/router'; @Component({ selector: 'app-forgot-password', @@ -9,23 +10,57 @@ import { ToastService } from '../services/toast.service'; }) export class ForgotPasswordPage implements OnInit { email: string = ''; + otp: string | number = ''; + newPassword: string = ''; + + stepType: 'EMAIL' | 'OTP' | 'RESET' = 'EMAIL'; constructor( private authService: AuthService, - private toastService: ToastService + private toastService: ToastService, + private router: Router ) { } ngOnInit() { } + ionViewDidEnter() { + document.querySelector('.menu-icon-holder').classList.add('hide'); + } + getOtp() { - this.authService.forgotPassword(this.email).then((data) => { - console.log(data); + this.authService.forgotPassword(this.email).then(() => { this.toastService.presentToast("OTP Sent to your Email ID", "success"); - }, (err) => { - console.log(err); + this.stepType = 'OTP'; + }, () => { this.toastService.presentToast("Failed to send OTP, Please check your credentials", "danger"); }); } + verifyOtp() { + this.authService.validateOtpForForgotPassword({ email: this.email, otp: this.otp }).then(() => { + this.toastService.presentToast("Verified", "success"); + this.stepType = 'RESET'; + }, () => { + this.toastService.presentToast("Verification failed, please try again", "danger"); + }); + } + + resetPassword() { + let credentials = { + email: this.email, + login_type: "user", + password: this.newPassword, + reEnteredPassword: this.newPassword + }; + + this.authService.resetPasswordForEmail(credentials).then(() => { + this.toastService.presentToast("Password Reset Complete", "success"); + this.router.navigate(['/login']); + this.stepType = 'EMAIL'; + }, () => { + this.toastService.presentToast("Please check your password", "danger"); + }); + } + } diff --git a/src/app/login/login.page.html b/src/app/login/login.page.html index 6f8ea16..e505598 100644 --- a/src/app/login/login.page.html +++ b/src/app/login/login.page.html @@ -11,7 +11,7 @@

- +
diff --git a/src/app/services/auth.service.ts b/src/app/services/auth.service.ts index ef879ab..620d1f3 100644 --- a/src/app/services/auth.service.ts +++ b/src/app/services/auth.service.ts @@ -16,19 +16,21 @@ export class AuthService { } forgotPassword(email: string) { - return this.http.post(URL + '/forgot', { email: email }).toPromise(); + return this.http.post(URL + '/forgot', { email: email }).toPromise(); } - validateOtpForEmail(data: { email: string, otp: number | string }) { - return this.http.post(URL + '/api/otp/validate', data).toPromise(); + resetPasswordForEmail(data: any) { + return this.http.post(URL + '/reset', data).toPromise(); } - // POST/api/auth/otpvalidate For Forgot password - - requestMailOTP(email: string) { - return this.http.post(URL + '/api/otp/generate/', { email: email }).toPromise(); + validateOtpForForgotPassword(data: { email: string, otp: number | string }) { + return this.http.post(URL + '/api/auth/otpvalidate', data).toPromise(); } + validateOtpForEmail(data: { email: string, otp: number | string }) { + return this.http.post(URL + '/api/otp/validate', data).toPromise(); + } + signupUser(credentials: any) { return this.http.post(URL + '/api/auth/signup/', credentials).toPromise(); }