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 @@
@@ -60,7 +78,7 @@ Login
{{response}}
-
+
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;
}
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")) {