store password hash in json user repo
This commit is contained in:
parent
a52bb18b13
commit
ada29ea957
1 changed files with 14 additions and 10 deletions
|
|
@ -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)) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue