diff --git a/frontend/src/app/account/profile/edit-password-dialog/edit-password-dialog.component.ts b/frontend/src/app/account/profile/edit-password-dialog/edit-password-dialog.component.ts index 7e47ffe67d..3f52c38781 100644 --- a/frontend/src/app/account/profile/edit-password-dialog/edit-password-dialog.component.ts +++ b/frontend/src/app/account/profile/edit-password-dialog/edit-password-dialog.component.ts @@ -88,70 +88,48 @@ export class EditPasswordDialogComponent { } onPasswordSubmit() { - if (this.editPasswordForm.valid) { - this.isProcessingPassword = true; + if (!this.editPasswordForm.valid) { + return; + } - // Check if password is correct first - this.authenticationService - .login(this.user!.username, this.editPasswordForm.get('oldPassword')?.value) - .subscribe({ - next: () => { - this.authenticationService - .updatePassword( - this.user!.username, - this.editPasswordForm.get('oldPassword')?.value, - this.editPasswordForm.get('password')?.value, - ) - .subscribe({ - next: () => { - // Reset states and forms on success - this.closeDialog(); + this.isProcessingPassword = true; - this.messageService.add({ - severity: 'success', - summary: 'Password Updated', - detail: 'Your password has been updated successfully!', - }); - }, - error: error => { - this.isProcessingPassword = false; - const status = error.cause.status; - let errorMessage = 'An unknown error occurred'; - if (status === 401) { - errorMessage = 'Try loging out and log back in. Expired token'; - } else if (status === 404) { - errorMessage = 'Try loging out and log back in. User ID Not Found'; - } else if (status === 409) { - errorMessage = 'Username or Email already exists'; - } else if (status === 500) { - errorMessage = 'Internal Server Error'; - } - this.messageService.add({ - severity: 'error', - summary: 'Editing Password Erorr', - detail: errorMessage, - }); - }, - }); - }, - error: error => { - this.isProcessingPassword = false; - const status = error.cause.status; - let errorMessage = 'An unknown error occurred'; - if (status === 400) { - errorMessage = 'Missing/Invalid passwords'; - } else if (status === 401) { - errorMessage = 'Your old password is invalid'; - } else if (status === 500) { - errorMessage = 'Internal Server Error'; - } - this.messageService.add({ - severity: 'error', - summary: 'Submission Error', - detail: errorMessage, - }); - }, - }); - } + this.authenticationService + .updatePassword( + this.user!.username, + this.editPasswordForm.get('oldPassword')?.value, + this.editPasswordForm.get('password')?.value, + ) + .subscribe({ + next: () => { + // Reset states and forms on success + this.closeDialog(); + + this.messageService.add({ + severity: 'success', + summary: 'Password Updated', + detail: 'Your password has been updated successfully!', + }); + }, + error: error => { + this.isProcessingPassword = false; + const status = error.cause.status; + let errorMessage = 'An unknown error occurred'; + if (status === 401) { + errorMessage = 'Try loging out and log back in. Expired token'; + } else if (status === 404) { + errorMessage = 'Try loging out and log back in. User ID Not Found'; + } else if (status === 409) { + errorMessage = 'Username or Email already exists'; + } else if (status === 500) { + errorMessage = 'Internal Server Error'; + } + this.messageService.add({ + severity: 'error', + summary: 'Editing Password Erorr', + detail: errorMessage, + }); + }, + }); } } diff --git a/frontend/src/app/account/profile/edit-profile-dialog/edit-profile-dialog.component.ts b/frontend/src/app/account/profile/edit-profile-dialog/edit-profile-dialog.component.ts index b9fb102bb9..66e941e782 100644 --- a/frontend/src/app/account/profile/edit-profile-dialog/edit-profile-dialog.component.ts +++ b/frontend/src/app/account/profile/edit-profile-dialog/edit-profile-dialog.component.ts @@ -61,65 +61,43 @@ export class EditProfileDialogComponent { } onEditSubmit() { - if (this.editProfileForm.valid) { - this.isProcessingEdit = true; + if (!this.editProfileForm.valid) { + return; + } - // Check if password is correct first - this.authenticationService - .login(this.user!.username, this.editProfileForm.get('password')?.value) - .subscribe({ - next: () => { - this.authenticationService - .updateUsernameAndEmail( - this.editProfileForm.get('username')?.value, - this.editProfileForm.get('email')?.value, - this.editProfileForm.get('password')?.value, - ) - .subscribe({ - next: () => { - this.closeDialog(); + this.isProcessingEdit = true; - this.messageService.add({ - severity: 'success', - summary: 'Profile Updated', - detail: 'Your profile has been updated successfully!', - }); - }, - error: error => { - this.isProcessingEdit = false; - const status = error.cause.status; - let errorMessage = 'An unknown error occurred'; - if (status === 401) { - errorMessage = 'Your session has expired. Please log out and log back in.'; - } else if (status === 409) { - errorMessage = 'The username or email already exists.'; - } - this.messageService.add({ - severity: 'error', - summary: 'Editing Profile Erorr', - detail: errorMessage, - }); - }, - }); - }, - error: error => { - this.isProcessingEdit = false; - const status = error.cause.status; - let errorMessage = 'An unknown error occurred'; - if (status === 400) { - errorMessage = 'Missing/Invalid passwords'; - } else if (status === 401) { - errorMessage = 'Your password is invalid'; - } else if (status === 500) { - errorMessage = 'Internal Server Error'; - } - this.messageService.add({ - severity: 'error', - summary: 'Submission Error', - detail: errorMessage, - }); - }, - }); - } + this.authenticationService + .updateUsernameAndEmail( + this.editProfileForm.get('username')?.value, + this.editProfileForm.get('email')?.value, + this.editProfileForm.get('password')?.value, + ) + .subscribe({ + next: () => { + this.closeDialog(); + + this.messageService.add({ + severity: 'success', + summary: 'Profile Updated', + detail: 'Your profile has been updated successfully!', + }); + }, + error: error => { + this.isProcessingEdit = false; + const status = error.cause.status; + let errorMessage = 'An unknown error occurred'; + if (status === 401) { + errorMessage = 'Your session has expired. Please log out and log back in.'; + } else if (status === 409) { + errorMessage = 'The username or email already exists.'; + } + this.messageService.add({ + severity: 'error', + summary: 'Editing Profile Erorr', + detail: errorMessage, + }); + }, + }); } } diff --git a/frontend/src/app/account/profile/profile.component.ts b/frontend/src/app/account/profile/profile.component.ts index e1c84c93ef..4daa895eda 100644 --- a/frontend/src/app/account/profile/profile.component.ts +++ b/frontend/src/app/account/profile/profile.component.ts @@ -9,7 +9,6 @@ import { ToastModule } from 'primeng/toast'; import { DividerModule } from 'primeng/divider'; import { InputTextModule } from 'primeng/inputtext'; import { FormUtilsService } from '../../../_services/form.utils.service'; -import { Router } from '@angular/router'; import { EditProfileDialogComponent } from './edit-profile-dialog/edit-profile-dialog.component'; import { EditPasswordDialogComponent } from './edit-password-dialog/edit-password-dialog.component'; @@ -37,8 +36,6 @@ export class ProfileComponent implements OnInit { constructor( private authenticationService: AuthenticationService, - private messageService: MessageService, - private router: Router, public formUtils: FormUtilsService, ) {} diff --git a/services/user/src/controller/user-controller.ts b/services/user/src/controller/user-controller.ts index 5c23cc2f49..d6d7451b79 100644 --- a/services/user/src/controller/user-controller.ts +++ b/services/user/src/controller/user-controller.ts @@ -104,12 +104,12 @@ export async function updateUsernameAndEmail(req: Request, res: Response) { const userByUsername = await _findUserByUsername(username); if (userByUsername && userByUsername.id !== userId) { - handleConflict(res, 'username already exists'); + handleConflict(res, 'The username already exists'); return; } const userByEmail = await _findUserByEmail(email); if (userByEmail && userByEmail.id !== userId) { - handleConflict(res, 'email already exists'); + handleConflict(res, 'The email already exists'); return; }