diff --git a/app/User/JsonUserRepository.php b/app/User/JsonUserRepository.php index 61f74b0..954ec48 100644 --- a/app/User/JsonUserRepository.php +++ b/app/User/JsonUserRepository.php @@ -22,6 +22,7 @@ class JsonUserRepository implements UserRepository $users[] = [ 'id' => $id, 'email' => (string) $dto->email, + 'passwordHash' => $dto->passwordHash, 'isAdmin' => $dto->isAdmin, ]; $this->writeUsers($users); @@ -29,6 +30,7 @@ class JsonUserRepository implements UserRepository return new User( id: $id, email: $dto->email, + passwordHash: $dto->passwordHash, isAdmin: $dto->isAdmin, ); } @@ -39,11 +41,7 @@ class JsonUserRepository implements UserRepository foreach ($users as $data) { if ($data['id'] === $id) { - return new User( - id: $data['id'], - email: new EmailAddress($data['email']), - isAdmin: $data['isAdmin'] ?? false, - ); + return $this->hydrate($data); } } @@ -56,17 +54,23 @@ class JsonUserRepository implements UserRepository foreach ($users as $data) { if ($data['email'] === (string) $email) { - return new User( - id: $data['id'], - email: new EmailAddress($data['email']), - isAdmin: $data['isAdmin'] ?? false, - ); + return $this->hydrate($data); } } return null; } + private function hydrate(array $data): User + { + return new User( + id: $data['id'], + email: new EmailAddress($data['email']), + passwordHash: $data['passwordHash'] ?? '', + isAdmin: $data['isAdmin'] ?? false, + ); + } + private function readUsers(): array { if (!file_exists($this->filePath)) {