From aab1138163acb474cc5c81b2f4abd7eff79733f9 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Thu, 21 Nov 2024 21:30:44 -0500 Subject: [PATCH] Update the user table to have the timestamps --- app/composer.lock | 66 ++++++++++--------- ...0241122022752_add_time_stamps_to_users.php | 24 +++++++ app/src/Controller/User/LoginUserAction.php | 2 +- .../Domain/Repository/User/UserRepository.php | 4 +- .../Database/DatabaseHandler.php | 12 ++-- 5 files changed, 68 insertions(+), 40 deletions(-) create mode 100644 app/db/migrations/20241122022752_add_time_stamps_to_users.php diff --git a/app/composer.lock b/app/composer.lock index e41bde4..38261f4 100644 --- a/app/composer.lock +++ b/app/composer.lock @@ -605,16 +605,16 @@ }, { "name": "laravel/serializable-closure", - "version": "v1.3.6", + "version": "v1.3.7", "source": { "type": "git", "url": "https://github.com/laravel/serializable-closure.git", - "reference": "f865a58ea3a0107c336b7045104c75243fa59d96" + "reference": "4f48ade902b94323ca3be7646db16209ec76be3d" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/f865a58ea3a0107c336b7045104c75243fa59d96", - "reference": "f865a58ea3a0107c336b7045104c75243fa59d96", + "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/4f48ade902b94323ca3be7646db16209ec76be3d", + "reference": "4f48ade902b94323ca3be7646db16209ec76be3d", "shasum": "" }, "require": { @@ -662,7 +662,7 @@ "issues": "https://github.com/laravel/serializable-closure/issues", "source": "https://github.com/laravel/serializable-closure" }, - "time": "2024-11-11T17:06:04+00:00" + "time": "2024-11-14T18:34:49+00:00" }, { "name": "league/config", @@ -2259,16 +2259,16 @@ }, { "name": "react/http", - "version": "v1.10.0", + "version": "v1.11.0", "source": { "type": "git", "url": "https://github.com/reactphp/http.git", - "reference": "8111281ee57f22b7194f5dba225e609ba7ce4d20" + "reference": "8db02de41dcca82037367f67a2d4be365b1c4db9" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/reactphp/http/zipball/8111281ee57f22b7194f5dba225e609ba7ce4d20", - "reference": "8111281ee57f22b7194f5dba225e609ba7ce4d20", + "url": "https://api.github.com/repos/reactphp/http/zipball/8db02de41dcca82037367f67a2d4be365b1c4db9", + "reference": "8db02de41dcca82037367f67a2d4be365b1c4db9", "shasum": "" }, "require": { @@ -2277,18 +2277,18 @@ "php": ">=5.3.0", "psr/http-message": "^1.0", "react/event-loop": "^1.2", - "react/promise": "^3 || ^2.3 || ^1.2.1", - "react/socket": "^1.12", - "react/stream": "^1.2" + "react/promise": "^3.2 || ^2.3 || ^1.2.1", + "react/socket": "^1.16", + "react/stream": "^1.4" }, "require-dev": { "clue/http-proxy-react": "^1.8", "clue/reactphp-ssh-proxy": "^1.4", "clue/socks-react": "^1.4", "phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", - "react/async": "^4 || ^3 || ^2", + "react/async": "^4.2 || ^3 || ^2", "react/promise-stream": "^1.4", - "react/promise-timer": "^1.9" + "react/promise-timer": "^1.11" }, "type": "library", "autoload": { @@ -2338,7 +2338,7 @@ ], "support": { "issues": "https://github.com/reactphp/http/issues", - "source": "https://github.com/reactphp/http/tree/v1.10.0" + "source": "https://github.com/reactphp/http/tree/v1.11.0" }, "funding": [ { @@ -2346,7 +2346,7 @@ "type": "open_collective" } ], - "time": "2024-03-27T17:20:46+00:00" + "time": "2024-11-20T15:24:08+00:00" }, { "name": "react/promise", @@ -4621,26 +4621,27 @@ }, { "name": "phpspec/prophecy", - "version": "v1.19.0", + "version": "v1.20.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy.git", - "reference": "67a759e7d8746d501c41536ba40cd9c0a07d6a87" + "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy/zipball/67a759e7d8746d501c41536ba40cd9c0a07d6a87", - "reference": "67a759e7d8746d501c41536ba40cd9c0a07d6a87", + "url": "https://api.github.com/repos/phpspec/prophecy/zipball/a0165c648cab6a80311c74ffc708a07bb53ecc93", + "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93", "shasum": "" }, "require": { "doctrine/instantiator": "^1.2 || ^2.0", - "php": "^7.2 || 8.0.* || 8.1.* || 8.2.* || 8.3.*", + "php": "^7.2 || 8.0.* || 8.1.* || 8.2.* || 8.3.* || 8.4.*", "phpdocumentor/reflection-docblock": "^5.2", "sebastian/comparator": "^3.0 || ^4.0 || ^5.0 || ^6.0", "sebastian/recursion-context": "^3.0 || ^4.0 || ^5.0 || ^6.0" }, "require-dev": { + "friendsofphp/php-cs-fixer": "^3.40", "phpspec/phpspec": "^6.0 || ^7.0", "phpstan/phpstan": "^1.9", "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0" @@ -4684,22 +4685,22 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy/issues", - "source": "https://github.com/phpspec/prophecy/tree/v1.19.0" + "source": "https://github.com/phpspec/prophecy/tree/v1.20.0" }, - "time": "2024-02-29T11:52:51+00:00" + "time": "2024-11-19T13:12:41+00:00" }, { "name": "phpspec/prophecy-phpunit", - "version": "v2.2.0", + "version": "v2.3.0", "source": { "type": "git", "url": "https://github.com/phpspec/prophecy-phpunit.git", - "reference": "16e1247e139434bce0bac09848bc5c8d882940fc" + "reference": "8819516c1b489ecee4c60db5f5432fac1ea8ac6f" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/16e1247e139434bce0bac09848bc5c8d882940fc", - "reference": "16e1247e139434bce0bac09848bc5c8d882940fc", + "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/8819516c1b489ecee4c60db5f5432fac1ea8ac6f", + "reference": "8819516c1b489ecee4c60db5f5432fac1ea8ac6f", "shasum": "" }, "require": { @@ -4707,6 +4708,9 @@ "phpspec/prophecy": "^1.18", "phpunit/phpunit": "^9.1 || ^10.1 || ^11.0" }, + "require-dev": { + "phpstan/phpstan": "^1.10" + }, "type": "library", "extra": { "branch-alias": { @@ -4736,9 +4740,9 @@ ], "support": { "issues": "https://github.com/phpspec/prophecy-phpunit/issues", - "source": "https://github.com/phpspec/prophecy-phpunit/tree/v2.2.0" + "source": "https://github.com/phpspec/prophecy-phpunit/tree/v2.3.0" }, - "time": "2024-03-01T08:33:58+00:00" + "time": "2024-11-19T13:24:17+00:00" }, { "name": "phpstan/phpdoc-parser", @@ -6244,12 +6248,12 @@ ], "aliases": [], "minimum-stability": "stable", - "stability-flags": {}, + "stability-flags": [], "prefer-stable": false, "prefer-lowest": false, "platform": { "ext-pdo": "*" }, - "platform-dev": {}, + "platform-dev": [], "plugin-api-version": "2.6.0" } diff --git a/app/db/migrations/20241122022752_add_time_stamps_to_users.php b/app/db/migrations/20241122022752_add_time_stamps_to_users.php new file mode 100644 index 0000000..9bf1904 --- /dev/null +++ b/app/db/migrations/20241122022752_add_time_stamps_to_users.php @@ -0,0 +1,24 @@ +auth->verify($credentials['password'], $user->getPassword())) { - $this->session->getFlash()->add('error', "Unable to login."); + $this->session->getFlash()->add('error', "Unable to login user."); return $this->render('user/login.twig')->withStatus(400); } diff --git a/app/src/Domain/Repository/User/UserRepository.php b/app/src/Domain/Repository/User/UserRepository.php index 72e50ec..7de4056 100644 --- a/app/src/Domain/Repository/User/UserRepository.php +++ b/app/src/Domain/Repository/User/UserRepository.php @@ -69,14 +69,14 @@ class UserRepository implements UserRepositoryInterface */ public function getFromEmail(string $email): User { - $query = "SELECT * FROM users WHERE email = :email LIMIT 1"; + $query = "SELECT * FROM users WHERE email = :email"; $results = $this->db->query($query, [ ':email' => $email ]); if (!is_array($results) || empty($results)) { throw new EntityNotFoundException("Unable to find User"); } - return $this->userFromQueryResults($results); + return $this->userFromQueryResults(array_shift($results)); } public function create(User $user): bool diff --git a/app/src/Infrastructure/Database/DatabaseHandler.php b/app/src/Infrastructure/Database/DatabaseHandler.php index a903239..02673fb 100644 --- a/app/src/Infrastructure/Database/DatabaseHandler.php +++ b/app/src/Infrastructure/Database/DatabaseHandler.php @@ -7,7 +7,7 @@ use PDO; class DatabaseHandler implements DatabaseHandlerInterface { - private PDO $pdo; + private PDO $handle; public function __construct( private string $host, @@ -16,7 +16,7 @@ class DatabaseHandler implements DatabaseHandlerInterface private string $database, private int $port = 3306 ) { - $this->pdo = new PDO( + $this->handle = new PDO( $this->getConnectionString(), $username, $password @@ -28,7 +28,7 @@ class DatabaseHandler implements DatabaseHandlerInterface */ public function getConnection() { - return $this->pdo; + return $this->handle; } public function getConnectionString(): string @@ -48,14 +48,14 @@ class DatabaseHandler implements DatabaseHandlerInterface public function query(string $query, array $params = []): array { - $statement = $this->database->prepare($query); + $statement = $this->handle->prepare($query); $statement->execute($params); - return $statement->fetchAll($params); + return $statement->fetchAll(PDO::FETCH_ASSOC); } public function execute(string $query, array $params = []): bool { - $statement = $this->database->prepare($query); + $statement = $this->handle->prepare($query); return $statement->execute($params); } }