From d207d9ac6f7c5d50ae32c9614740bf4003c1ad8a Mon Sep 17 00:00:00 2001
From: kj1352
Date: Thu, 3 Dec 2020 14:08:14 +0530
Subject: [PATCH] Reset Password API connection and UI
---
.../forgot-password/forgot-password.page.html | 66 ++++++++++++++-----
.../forgot-password/forgot-password.page.ts | 45 +++++++++++--
src/app/login/login.page.html | 2 +-
src/app/services/auth.service.ts | 16 +++--
4 files changed, 100 insertions(+), 29 deletions(-)
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 @@
-
-
-
- Please enter to your email
-
-
-
-
-
-
- Get OTP
-
- Login
-
+
+
+
+ Please enter to your email
+
+
+
+
+
+
+ Get OTP
+
+ Login
+
+
+
+
+
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();
}