-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add login; add users and actions; write some tests
- Loading branch information
1 parent
61c2d3d
commit 69d2bbf
Showing
68 changed files
with
1,379 additions
and
100 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
root * /var/www/html/public | ||
php_fastcgi php:9000 | ||
file_server | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,9 @@ docker-compose exec php php bin/console.php app:database-migration | |
docker-compose exec php php bin/console.php app:database-fixture | ||
|
||
# Visit http://localhost:8080 | ||
|
||
# Test-Account-Mail: [email protected] | ||
# Test-Account-Password: Password123 | ||
``` | ||
|
||
### Prod | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
CREATE TABLE IF NOT EXISTS users ( | ||
uuid TEXT PRIMARY KEY, | ||
email TEXT NOT NULL, | ||
password TEXT NOT NULL, | ||
created DATETIME NOT NULL | ||
); | ||
|
||
CREATE UNIQUE INDEX users_email_unique_index ON users(email); | ||
CREATE INDEX users_created_index ON users(created); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,3 @@ parameters: | |
- public | ||
- src | ||
- tests | ||
ignoreErrors: | ||
- '#Constant ROOT_DIR not found.#' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action; | ||
|
||
use DateTimeImmutable; | ||
use Jesperbeisner\Fwstats\Action\Exception\ActionException; | ||
use Jesperbeisner\Fwstats\Action\Interface\ActionInterface; | ||
use Jesperbeisner\Fwstats\Action\Interface\ActionResultInterface; | ||
use Jesperbeisner\Fwstats\Action\Result\CreateUserActionResult; | ||
use Jesperbeisner\Fwstats\Helper\UuidV4; | ||
use Jesperbeisner\Fwstats\Model\User; | ||
use Jesperbeisner\Fwstats\Repository\UserRepository; | ||
|
||
final class CreateUserAction implements ActionInterface | ||
{ | ||
private string $email; | ||
private string $password; | ||
|
||
public function __construct( | ||
private readonly UserRepository $userRepository | ||
) { | ||
} | ||
|
||
public function configure(array $data): void | ||
{ | ||
if (empty($data['email'])) { | ||
throw new ActionException("No email set in the 'AbstractAction::configure' method."); | ||
} | ||
|
||
if (empty($data['password'])) { | ||
throw new ActionException("No password set in the 'AbstractAction::configure' method."); | ||
} | ||
|
||
if (!is_string($data['email'])) { | ||
throw new ActionException("The email set in the 'AbstractAction::configure' method is not a string."); | ||
} | ||
|
||
if (!is_string($data['password'])) { | ||
throw new ActionException("The password set in the 'AbstractAction::configure' method is not a string."); | ||
} | ||
|
||
if (filter_var($data['email'], FILTER_VALIDATE_EMAIL) === false) { | ||
throw new ActionException("The email '{$data['email']}' is not valid email address."); | ||
} | ||
|
||
if (strlen($data['password']) < 8) { | ||
throw new ActionException("The password must be at least 8 characters long."); | ||
} | ||
|
||
$this->email = $data['email']; | ||
$this->password = $data['password']; | ||
} | ||
|
||
public function run(): CreateUserActionResult | ||
{ | ||
if (null !== $this->userRepository->findOneByEmail($this->email)) { | ||
throw new ActionException("A user with email '$this->email' already exists."); | ||
} | ||
|
||
$hashedPassword = password_hash($this->password, PASSWORD_DEFAULT); | ||
|
||
$user = new User(UuidV4::create(), $this->email, $hashedPassword, new DateTimeImmutable()); | ||
|
||
$this->userRepository->insert($user); | ||
|
||
return new CreateUserActionResult(ActionResultInterface::SUCCESS, ['user' => $user]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action\Exception; | ||
|
||
use RuntimeException; | ||
|
||
final class ActionException extends RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action\Exception; | ||
|
||
use RuntimeException; | ||
|
||
final class ActionResultException extends RuntimeException | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action\Factory; | ||
|
||
use Jesperbeisner\Fwstats\Action\CreateUserAction; | ||
use Jesperbeisner\Fwstats\Repository\UserRepository; | ||
use Jesperbeisner\Fwstats\Stdlib\Interface\FactoryInterface; | ||
use Psr\Container\ContainerInterface; | ||
|
||
class CreateUserActionFactory implements FactoryInterface | ||
{ | ||
public function __invoke(ContainerInterface $serviceContainer, string $serviceName): CreateUserAction | ||
{ | ||
/** @var UserRepository $userRepository */ | ||
$userRepository = $serviceContainer->get(UserRepository::class); | ||
|
||
return new CreateUserAction( | ||
$userRepository, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action\Interface; | ||
|
||
interface ActionInterface | ||
{ | ||
/** | ||
* @param mixed[] $data | ||
*/ | ||
public function configure(array $data): void; | ||
|
||
public function run(): ActionResultInterface; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action\Interface; | ||
|
||
interface ActionResultInterface | ||
{ | ||
public const SUCCESS = 0; | ||
public const FAILURE = 1; | ||
|
||
public function isSuccess(): bool; | ||
|
||
/** | ||
* @return mixed[] | ||
*/ | ||
public function getData(): array; | ||
|
||
public function getMessage(): string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action\Result; | ||
|
||
use Jesperbeisner\Fwstats\Action\Exception\ActionResultException; | ||
use Jesperbeisner\Fwstats\Action\Interface\ActionResultInterface; | ||
|
||
abstract class AbstractActionResult implements ActionResultInterface | ||
{ | ||
protected readonly int $result; | ||
|
||
/** @var mixed[] */ | ||
protected readonly array $data; | ||
protected readonly string $message; | ||
|
||
/** | ||
* @param mixed[] $data | ||
*/ | ||
public function __construct(int $result, array $data = [], string $message = '') | ||
{ | ||
if (!in_array($result, [self::SUCCESS, self::FAILURE], true)) { | ||
throw new ActionResultException('Only 0 and 1 are valid values for $result.'); | ||
} | ||
|
||
$this->result = $result; | ||
$this->data = $data; | ||
$this->message = $message; | ||
} | ||
|
||
public function isSuccess(): bool | ||
{ | ||
return $this->result === self::SUCCESS; | ||
} | ||
public function getData(): array | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function getMessage(): string | ||
{ | ||
return $this->message; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Jesperbeisner\Fwstats\Action\Result; | ||
|
||
use Jesperbeisner\Fwstats\Action\Exception\ActionResultException; | ||
use Jesperbeisner\Fwstats\Model\User; | ||
|
||
final class CreateUserActionResult extends AbstractActionResult | ||
{ | ||
public function getUser(): User | ||
{ | ||
if (isset($this->data['user']) && $this->data['user'] instanceof User) { | ||
return $this->data['user']; | ||
} | ||
|
||
throw new ActionResultException('No user in data array available.'); | ||
} | ||
} |
Oops, something went wrong.