Skip to content
This repository was archived by the owner on Feb 13, 2023. It is now read-only.

Commit 5a76c2b

Browse files
authored
bugfix(user) fix unnecessary sending password changing email (#1549)
1 parent d149329 commit 5a76c2b

File tree

3 files changed

+64
-8
lines changed

3 files changed

+64
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11

22
## CHANGELOG FOR 1.0.x
3+
#### 1.0.4
4+
- bugfix [#1548](https://github.com/ergonode/backend/issues/1548) Plain text password in CreateUserEvent (rprzedzik)
5+
- bugfix [#1545](https://github.com/ergonode/backend/issues/1545) Unnecessary sending of password changing e-mail (rprzedzik)
6+
37
#### 1.0.3
48
- bugfix [#1526](https://github.com/ergonode/backend/issues/1526) Opened gesdinet/jwt-refresh-token-bundle dependency (piotrkreft)
59
- bugfix [#1522](https://github.com/ergonode/backend/issues/1522) Remove ramsey/uuid-doctrine composer relation (wfajczyk)
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
/**
4+
* Copyright © Ergonode Sp. z o.o. All rights reserved.
5+
* See LICENSE.txt for license details.
6+
*/
7+
8+
declare(strict_types=1);
9+
10+
namespace Ergonode\Migration;
11+
12+
use Doctrine\DBAL\Schema\Schema;
13+
use Ergonode\Account\Domain\Event\User\UserPasswordChangedEvent;
14+
use Doctrine\DBAL\FetchMode;
15+
16+
class Version20210728123000 extends AbstractErgonodeMigration
17+
{
18+
public function up(Schema $schema): void
19+
{
20+
$eventId = $this->connection->executeQuery(
21+
'SELECT id FROM event_store_event WHERE event_class = :class',
22+
[
23+
'class' => UserPasswordChangedEvent::class,
24+
]
25+
)->fetch(FetchMode::COLUMN);
26+
27+
$aggregates = $this->connection->executeQuery(
28+
'SELECT aggregate_id, payload->\'password\' as password
29+
FROM event_store WHERE event_id = :id AND sequence = 2',
30+
[
31+
'id' => $eventId,
32+
]
33+
)->fetchAll();
34+
35+
foreach ($aggregates as $aggregate) {
36+
$this->addSql(
37+
'UPDATE event_store SET payload = jsonb_set(payload, \'{password}\',:password::JSONB)
38+
WHERE aggregate_id = :id and sequence = 1',
39+
[
40+
'password' => $aggregate['password'],
41+
'id' => $aggregate['aggregate_id'],
42+
]
43+
);
44+
}
45+
}
46+
}

module/account/src/Infrastructure/Handler/CreateUserCommandHandler.php

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Ergonode\Account\Infrastructure\Encoder\UserPasswordEncoderInterface;
1616
use Ergonode\Core\Domain\Query\LanguageQueryInterface;
1717
use Ergonode\Core\Domain\ValueObject\LanguagePrivileges;
18+
use Ergonode\Account\Domain\ValueObject\Password;
1819

1920
class CreateUserCommandHandler
2021
{
@@ -44,21 +45,26 @@ public function __invoke(CreateUserCommand $command): void
4445
foreach ($activeLanguages as $activeLanguage) {
4546
$languagePrivilegesCollection[$activeLanguage->getCode()] = new LanguagePrivileges(true, true);
4647
}
47-
$user = new User(
48+
49+
$plainPasswordUser = $this->createUser($command, $command->getPassword(), $languagePrivilegesCollection);
50+
$encodedPassword = $this->userPasswordEncoder->encode($plainPasswordUser, $command->getPassword());
51+
$user = $this->createUser($command, $encodedPassword, $languagePrivilegesCollection);
52+
53+
$this->repository->save($user);
54+
}
55+
56+
private function createUser(CreateUserCommand $command, Password $password, array $languagePrivilege): User
57+
{
58+
return new User(
4859
$command->getId(),
4960
$command->getFirstName(),
5061
$command->getLastName(),
5162
$command->getEmail(),
5263
$command->getLanguage(),
53-
$command->getPassword(),
64+
$password,
5465
$command->getRoleId(),
55-
$languagePrivilegesCollection,
66+
$languagePrivilege,
5667
$command->isActive()
5768
);
58-
59-
$encodedPassword = $this->userPasswordEncoder->encode($user, $command->getPassword());
60-
$user->changePassword($encodedPassword);
61-
62-
$this->repository->save($user);
6369
}
6470
}

0 commit comments

Comments
 (0)