diff --git a/backend/src/entities/user/application/data-structures/change-usual-user-password.ds.ts b/backend/src/entities/user/application/data-structures/change-usual-user-password.ds.ts index a11523fa9..295501afc 100644 --- a/backend/src/entities/user/application/data-structures/change-usual-user-password.ds.ts +++ b/backend/src/entities/user/application/data-structures/change-usual-user-password.ds.ts @@ -1,7 +1,7 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsNotEmpty, IsString, IsEmail, IsStrongPassword, MaxLength } from 'class-validator'; -export class ChangeUsualUserPasswordDs { +export class ChangeUsualUserPasswordDto { @ApiProperty() @IsNotEmpty() @IsString() @@ -26,3 +26,7 @@ export class ChangeUsualUserPasswordDs { @IsString() oldPassword: string; } + +export class ChangeUsualUserPasswordDs extends ChangeUsualUserPasswordDto { + userId: string; +} \ No newline at end of file diff --git a/backend/src/entities/user/use-cases/change-usual-password-use.case.ts b/backend/src/entities/user/use-cases/change-usual-password-use.case.ts index a8f8363d1..bb02e55bf 100644 --- a/backend/src/entities/user/use-cases/change-usual-password-use.case.ts +++ b/backend/src/entities/user/use-cases/change-usual-password-use.case.ts @@ -4,14 +4,17 @@ import { IGlobalDatabaseContext } from '../../../common/application/global-datab import { BaseType } from '../../../common/data-injection.tokens.js'; import { Messages } from '../../../exceptions/text/messages.js'; import { Encryptor } from '../../../helpers/encryption/encryptor.js'; -import { ChangeUsualUserPasswordDs } from '../application/data-structures/change-usual-user-password.ds.js'; +import { + ChangeUsualUserPasswordDs, + ChangeUsualUserPasswordDto, +} from '../application/data-structures/change-usual-user-password.ds.js'; import { generateGwtToken, IToken } from '../utils/generate-gwt-token.js'; import { IUsualPasswordChange } from './user-use-cases.interfaces.js'; import { get2FaScope } from '../utils/is-jwt-scope-need.util.js'; @Injectable() export class ChangeUsualPasswordUseCase - extends AbstractUseCase + extends AbstractUseCase implements IUsualPasswordChange { constructor( @@ -22,7 +25,7 @@ export class ChangeUsualPasswordUseCase } protected async implementation(userData: ChangeUsualUserPasswordDs): Promise { - const user = await this._dbContext.userRepository.findOneUserByEmail(userData.email); + const user = await this._dbContext.userRepository.findOneUserById(userData.email); if (!user) { throw new NotFoundException(Messages.USER_NOT_FOUND); } diff --git a/backend/src/entities/user/use-cases/user-use-cases.interfaces.ts b/backend/src/entities/user/use-cases/user-use-cases.interfaces.ts index 0d02d10ef..d831b57d3 100644 --- a/backend/src/entities/user/use-cases/user-use-cases.interfaces.ts +++ b/backend/src/entities/user/use-cases/user-use-cases.interfaces.ts @@ -1,7 +1,7 @@ import { InTransactionEnum } from '../../../enums/index.js'; import { ChangeUserEmailDs } from '../application/data-structures/change-user-email.ds.js'; import { ChangeUserNameDS } from '../application/data-structures/change-user-name.ds.js'; -import { ChangeUsualUserPasswordDs } from '../application/data-structures/change-usual-user-password.ds.js'; +import { ChangeUsualUserPasswordDto } from '../application/data-structures/change-usual-user-password.ds.js'; import { CreateUserDs } from '../application/data-structures/create-user.ds.js'; import { CreatedUserDs } from '../application/data-structures/created-user.ds.js'; import { FindUserDs } from '../application/data-structures/find-user.ds.js'; @@ -56,7 +56,7 @@ export interface IFacebookLogin { } export interface IUsualPasswordChange { - execute(inputData: ChangeUsualUserPasswordDs, inTransaction: InTransactionEnum): Promise; + execute(inputData: ChangeUsualUserPasswordDto, inTransaction: InTransactionEnum): Promise; } export interface IVerifyEmail { diff --git a/backend/src/entities/user/user.controller.ts b/backend/src/entities/user/user.controller.ts index b4e4d905f..1b9e77c56 100644 --- a/backend/src/entities/user/user.controller.ts +++ b/backend/src/entities/user/user.controller.ts @@ -25,7 +25,7 @@ import { Constants } from '../../helpers/constants/constants.js'; import { SentryInterceptor } from '../../interceptors/index.js'; import { ChangeUserEmailDs } from './application/data-structures/change-user-email.ds.js'; import { ChangeUserNameDS } from './application/data-structures/change-user-name.ds.js'; -import { ChangeUsualUserPasswordDs } from './application/data-structures/change-usual-user-password.ds.js'; +import { ChangeUsualUserPasswordDs, ChangeUsualUserPasswordDto } from './application/data-structures/change-usual-user-password.ds.js'; import { FindUserDs } from './application/data-structures/find-user.ds.js'; import { FoundUserDto } from './dto/found-user.dto.js'; import { OperationResultMessageDs } from './application/data-structures/operation-result-message.ds.js'; @@ -198,7 +198,7 @@ export class UserController { } @ApiOperation({ summary: 'Change user password' }) - @ApiBody({ type: ChangeUsualUserPasswordDs }) + @ApiBody({ type: ChangeUsualUserPasswordDto }) @ApiResponse({ status: 201, description: 'Change user password.', @@ -207,13 +207,15 @@ export class UserController { @Post('user/password/change/') async changeUsualPassword( @Res({ passthrough: true }) response: Response, - @Body() changePasswordData: ChangeUsualUserPasswordDs, + @Body() changePasswordData: ChangeUsualUserPasswordDto, + @UserId() userId: string, ): Promise { const { email, newPassword, oldPassword } = changePasswordData; const inputData: ChangeUsualUserPasswordDs = { email: email, newPassword: newPassword, oldPassword: oldPassword, + userId: userId, }; const tokenInfo = await this.changeUsualPasswordUseCase.execute(inputData, InTransactionEnum.ON); response.cookie(Constants.JWT_COOKIE_KEY_NAME, tokenInfo.token, { diff --git a/backend/src/entities/user/user.module.ts b/backend/src/entities/user/user.module.ts index bb9b241ca..371520fe5 100644 --- a/backend/src/entities/user/user.module.ts +++ b/backend/src/entities/user/user.module.ts @@ -158,6 +158,7 @@ export class UserModule implements NestModule { { path: 'user/settings', method: RequestMethod.POST }, { path: 'user/settings', method: RequestMethod.GET }, { path: 'user/test/connections/display/', method: RequestMethod.PUT }, + { path: 'user/password/change', method: RequestMethod.POST }, ) .apply(TemporaryAuthMiddleware) .forRoutes({ path: 'user/otp/login', method: RequestMethod.POST })