From 08ad0e14825e3cde2b3985e92b83341db035e8ba Mon Sep 17 00:00:00 2001 From: code1ogic <96641204+code1ogic@users.noreply.github.com> Date: Sun, 2 Apr 2023 08:24:49 +0530 Subject: [PATCH 1/3] Update auth.service.ts --- frontend/src/app/service/auth.service.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/frontend/src/app/service/auth.service.ts b/frontend/src/app/service/auth.service.ts index b40b748..d99ba5e 100644 --- a/frontend/src/app/service/auth.service.ts +++ b/frontend/src/app/service/auth.service.ts @@ -18,6 +18,10 @@ export class AuthService { register(user : User) : Observable { return this.http.post(this.apiUrl+'register', user); } + + verifyOTP(user : User) : Observable { + return this.http.post(this.apiUrl+'verifyOtp', user); + } isUserLoggedIn() : Boolean{ if(localStorage.getItem("user_id")) { From 2cf7214e746c47d6b88c8ac9ddc58c4c6b613a96 Mon Sep 17 00:00:00 2001 From: code1ogic <96641204+code1ogic@users.noreply.github.com> Date: Sun, 2 Apr 2023 08:27:07 +0530 Subject: [PATCH 2/3] Update login.component.ts --- .../component/auth/login/login.component.ts | 39 ++++++++++++++++++- 1 file changed, 37 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/component/auth/login/login.component.ts b/frontend/src/app/component/auth/login/login.component.ts index 9f3851f..8ec0871 100644 --- a/frontend/src/app/component/auth/login/login.component.ts +++ b/frontend/src/app/component/auth/login/login.component.ts @@ -15,18 +15,24 @@ export class LoginComponent implements OnInit { @ViewChild('modal') modal: ElementRef | undefined; - + isLogingSuccess : boolean = false; userObject : User = { _id: '', email: '', name: '', password: '' }; + count : number = 3; response : String =''; userLoginData = new UntypedFormGroup({ email : new UntypedFormControl(), password : new UntypedFormControl() }) + + userOTP = new UntypedFormGroup({ + otp : new UntypedFormControl(), + userId : new UntypedFormControl() + }) showPassword : boolean = false; constructor(private fb : UntypedFormBuilder, private auth : AuthService, private route : Router) { } @@ -36,6 +42,9 @@ export class LoginComponent implements OnInit { email : ['',[Validators.required, Validators.email]], password : ['',[Validators.required]] }); + this.userOTP = this.fb.group({ + otp : ['',[Validators.required]] + }); this.response = ""; } @@ -46,13 +55,39 @@ export class LoginComponent implements OnInit { this.auth.login(this.userObject).subscribe(res => { console.log(res); localStorage.setItem("user_id", res._id); + this.isLogingSuccess = true; + //this.route.navigate(['/dashboard']); + }, err => { + this.response = err.error.msg; + this.modal?.nativeElement.click(); + }) + } + + verifyOtp() { + if(this.count < 1) { + this.response = "You have reached maximum attempts for verifying OTP"; + this.modal?.nativeElement.click(); + return; + } + + this.userObject.otp = this.userOTP.value.otp; + this.userObject.userId = localStorage.getItem("user_id"); + this.count = this.count - 1; + this.auth.verifyOTP(this.userObject).subscribe(res => { this.route.navigate(['/dashboard']); }, err => { this.response = err.error.msg; this.modal?.nativeElement.click(); }) } - + + closeModel() { + if(this.count < 1) { + this.route.navigate(['/']); + return; + } + } + changePasswordProperty() { this.showPassword = !this.showPassword; } From c90524d751103868f635a774c2138161902c7cf2 Mon Sep 17 00:00:00 2001 From: code1ogic <96641204+code1ogic@users.noreply.github.com> Date: Sun, 2 Apr 2023 08:27:45 +0530 Subject: [PATCH 3/3] Update login.component.html --- .../component/auth/login/login.component.html | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/frontend/src/app/component/auth/login/login.component.html b/frontend/src/app/component/auth/login/login.component.html index 6ed76f9..655f885 100644 --- a/frontend/src/app/component/auth/login/login.component.html +++ b/frontend/src/app/component/auth/login/login.component.html @@ -4,7 +4,7 @@
-
+

Login


@@ -43,7 +43,25 @@

Login

+ +
+

Login

+
+
+ + +
+ This is required field +
+
+ +
+ +
+ +
+
@@ -60,7 +78,7 @@

Login

- +