From 01d3732e17244c05c2d929d42f727a969deddf97 Mon Sep 17 00:00:00 2001 From: WingZer0o Date: Sun, 10 Mar 2024 01:28:39 -0500 Subject: [PATCH 1/3] start of enabling 2FA with checkbox --- .../user-home/user-settings/user-settings.component.html | 6 ++++++ .../user-home/user-settings/user-settings.component.ts | 4 ++++ 2 files changed, 10 insertions(+) diff --git a/src/app/modules/user-home/user-settings/user-settings.component.html b/src/app/modules/user-home/user-settings/user-settings.component.html index 5bc2edc..d44d5f5 100644 --- a/src/app/modules/user-home/user-settings/user-settings.component.html +++ b/src/app/modules/user-home/user-settings/user-settings.component.html @@ -65,5 +65,11 @@ } +
+ + +
\ No newline at end of file diff --git a/src/app/modules/user-home/user-settings/user-settings.component.ts b/src/app/modules/user-home/user-settings/user-settings.component.ts index 8a2fca5..4ce4898 100644 --- a/src/app/modules/user-home/user-settings/user-settings.component.ts +++ b/src/app/modules/user-home/user-settings/user-settings.component.ts @@ -39,6 +39,10 @@ export class UserSettingsComponent implements OnInit { }); } + public handle2FAChange(event: any) { + let isChecked: boolean = event.target.checked; + } + public newUsernameSubmit(): void { if (this.userNameForm.valid) { this.isNewUsernameSubmitted = true; From 7bf6abd20522abfe4e604797be780da87a0a7701 Mon Sep 17 00:00:00 2001 From: WingZer0o Date: Sun, 10 Mar 2024 06:47:30 -0400 Subject: [PATCH 2/3] #12 2fa email refactor beginning --- .../modules/login/login/login.component.ts | 1 + .../user-settings.component.html | 2 +- .../user-settings/user-settings.component.ts | 30 +++++++++++++++++++ 3 files changed, 32 insertions(+), 1 deletion(-) diff --git a/src/app/modules/login/login/login.component.ts b/src/app/modules/login/login/login.component.ts index ca605c8..34c31db 100644 --- a/src/app/modules/login/login/login.component.ts +++ b/src/app/modules/login/login/login.component.ts @@ -58,6 +58,7 @@ export class LoginComponent implements OnInit { this.isSubmitClicked = false; this.loginForm.reset(); localStorage.setItem("token", response.token); + this.isTwoFactorForm = response.TwoFactorAuth; this.navbarEmitter.navbarEvents("user-logged-in"); // check if user has token stored if (response.twoFactorAuth === true) { diff --git a/src/app/modules/user-home/user-settings/user-settings.component.html b/src/app/modules/user-home/user-settings/user-settings.component.html index d44d5f5..a331722 100644 --- a/src/app/modules/user-home/user-settings/user-settings.component.html +++ b/src/app/modules/user-home/user-settings/user-settings.component.html @@ -66,7 +66,7 @@ }
- + diff --git a/src/app/modules/user-home/user-settings/user-settings.component.ts b/src/app/modules/user-home/user-settings/user-settings.component.ts index 4ce4898..68cb33d 100644 --- a/src/app/modules/user-home/user-settings/user-settings.component.ts +++ b/src/app/modules/user-home/user-settings/user-settings.component.ts @@ -16,6 +16,7 @@ export class UserSettingsComponent implements OnInit { public userPasswordForm: FormGroup; public isNewUsernameSubmitted: boolean = false; public isNewPasswordSubmitted: boolean = false; + public two2FAEnabled: boolean = false; constructor( private formBuilder: FormBuilder, @@ -37,10 +38,39 @@ export class UserSettingsComponent implements OnInit { confirmNewPassword: ['', [Validators.required, passwordValidator]], currentPassword: ['', [Validators.required, passwordValidator]] }); + + this.get2FAStatus(); + } + + private get2FAStatus(): void { + const url = environment.apiUrl + "TwoFA/Get2FAStatus"; + this.httpService.getAuthenticated(url).subscribe((response: any) => { + this.two2FAEnabled = response.result; + }); + } + + private change2FAToDisabled(): void { + const url = environment.apiUrl + "TwoFA/TurnOff2FA"; + this.httpService.putAuthenticated(url, null).subscribe((response: any) => { + this.two2FAEnabled = false; + }); + } + + private chang2FAToEnabled(): void { + const url = environment.apiUrl + "TwoFA/TurnOn2FA"; + this.httpService.putAuthenticated(url, null).subscribe((response: any) => { + this.two2FAEnabled = true; + }); } public handle2FAChange(event: any) { + debugger; let isChecked: boolean = event.target.checked; + if (isChecked) { + this.chang2FAToEnabled(); + } else { + this.change2FAToDisabled(); + } } public newUsernameSubmit(): void { From fb73f99da2a50f4453f26ca583bbf5c85dc92575 Mon Sep 17 00:00:00 2001 From: WingZer0o Date: Sun, 10 Mar 2024 09:58:59 -0400 Subject: [PATCH 3/3] #15 refactor for 2FA email --- .../modules/login/login/login.component.ts | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/src/app/modules/login/login/login.component.ts b/src/app/modules/login/login/login.component.ts index 34c31db..2c32c68 100644 --- a/src/app/modules/login/login/login.component.ts +++ b/src/app/modules/login/login/login.component.ts @@ -22,6 +22,8 @@ export class LoginComponent implements OnInit { public isSubmitClicked: boolean = false; public isTwoFactorForm: boolean = false; public isTwoFactorFormSubmitted: boolean = false; + private userId: string; + public loginForm: FormGroup = this.formBuilder.group({ email: ['', [Validators.required, Validators.email] @@ -29,6 +31,7 @@ export class LoginComponent implements OnInit { password: ['', [Validators.required, passwordValidator]] }); + public twoFAForm: FormGroup = this.formBuilder.group({ code: ['', [Validators.required, Validators.minLength(8)]] }); @@ -57,7 +60,12 @@ export class LoginComponent implements OnInit { this.toastr.success("", response.message); this.isSubmitClicked = false; this.loginForm.reset(); - localStorage.setItem("token", response.token); + if (response.token) { + localStorage.setItem("token", response.token); + } + if (response.userId) { + this.userId = response.userId; + } this.isTwoFactorForm = response.TwoFactorAuth; this.navbarEmitter.navbarEvents("user-logged-in"); // check if user has token stored @@ -101,10 +109,12 @@ export class LoginComponent implements OnInit { public twoFactorCodeSubmit(event: any): void { if (!this.isTwoFactorFormSubmitted && this.twoFAForm.valid) { this.isTwoFactorFormSubmitted = true; - let decodedToken = this.authGuard.getDecodedToken(); - let body = this.getPutTwoFAVerificationBody(decodedToken); - this.http.putAuthenticated(environment.apiUrl + "UserLogin/ValidateHotpCode", body).subscribe((response: any) => { + let body = this.getPutTwoFAVerificationBody(); + this.http.putAuthenticated("UserLogin/ValidateHotpCode", body).subscribe((response: any) => { this.isTwoFactorFormSubmitted = false; + if (response.token) { + localStorage.setItem("token", response.token); + } this.toastr.success(response.message, ""); setTimeout(() => { this.router.navigate(['/user-home']); @@ -116,9 +126,9 @@ export class LoginComponent implements OnInit { } } - private getPutTwoFAVerificationBody(decodedToken: any): object { + private getPutTwoFAVerificationBody(): object { return { - "UserId": decodedToken["id"], + "UserId": this.userId, "HotpCode": this.twoFAForm.value["code"] } }