Compare commits

..

2 Commits

6 changed files with 83 additions and 41 deletions

66
app/composer.lock generated
View File

@ -605,16 +605,16 @@
}, },
{ {
"name": "laravel/serializable-closure", "name": "laravel/serializable-closure",
"version": "v1.3.6", "version": "v1.3.7",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/laravel/serializable-closure.git", "url": "https://github.com/laravel/serializable-closure.git",
"reference": "f865a58ea3a0107c336b7045104c75243fa59d96" "reference": "4f48ade902b94323ca3be7646db16209ec76be3d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/laravel/serializable-closure/zipball/f865a58ea3a0107c336b7045104c75243fa59d96", "url": "https://api.github.com/repos/laravel/serializable-closure/zipball/4f48ade902b94323ca3be7646db16209ec76be3d",
"reference": "f865a58ea3a0107c336b7045104c75243fa59d96", "reference": "4f48ade902b94323ca3be7646db16209ec76be3d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -662,7 +662,7 @@
"issues": "https://github.com/laravel/serializable-closure/issues", "issues": "https://github.com/laravel/serializable-closure/issues",
"source": "https://github.com/laravel/serializable-closure" "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", "name": "league/config",
@ -2259,16 +2259,16 @@
}, },
{ {
"name": "react/http", "name": "react/http",
"version": "v1.10.0", "version": "v1.11.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/reactphp/http.git", "url": "https://github.com/reactphp/http.git",
"reference": "8111281ee57f22b7194f5dba225e609ba7ce4d20" "reference": "8db02de41dcca82037367f67a2d4be365b1c4db9"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/reactphp/http/zipball/8111281ee57f22b7194f5dba225e609ba7ce4d20", "url": "https://api.github.com/repos/reactphp/http/zipball/8db02de41dcca82037367f67a2d4be365b1c4db9",
"reference": "8111281ee57f22b7194f5dba225e609ba7ce4d20", "reference": "8db02de41dcca82037367f67a2d4be365b1c4db9",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2277,18 +2277,18 @@
"php": ">=5.3.0", "php": ">=5.3.0",
"psr/http-message": "^1.0", "psr/http-message": "^1.0",
"react/event-loop": "^1.2", "react/event-loop": "^1.2",
"react/promise": "^3 || ^2.3 || ^1.2.1", "react/promise": "^3.2 || ^2.3 || ^1.2.1",
"react/socket": "^1.12", "react/socket": "^1.16",
"react/stream": "^1.2" "react/stream": "^1.4"
}, },
"require-dev": { "require-dev": {
"clue/http-proxy-react": "^1.8", "clue/http-proxy-react": "^1.8",
"clue/reactphp-ssh-proxy": "^1.4", "clue/reactphp-ssh-proxy": "^1.4",
"clue/socks-react": "^1.4", "clue/socks-react": "^1.4",
"phpunit/phpunit": "^9.6 || ^5.7 || ^4.8.36", "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-stream": "^1.4",
"react/promise-timer": "^1.9" "react/promise-timer": "^1.11"
}, },
"type": "library", "type": "library",
"autoload": { "autoload": {
@ -2338,7 +2338,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/reactphp/http/issues", "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": [ "funding": [
{ {
@ -2346,7 +2346,7 @@
"type": "open_collective" "type": "open_collective"
} }
], ],
"time": "2024-03-27T17:20:46+00:00" "time": "2024-11-20T15:24:08+00:00"
}, },
{ {
"name": "react/promise", "name": "react/promise",
@ -4621,26 +4621,27 @@
}, },
{ {
"name": "phpspec/prophecy", "name": "phpspec/prophecy",
"version": "v1.19.0", "version": "v1.20.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpspec/prophecy.git", "url": "https://github.com/phpspec/prophecy.git",
"reference": "67a759e7d8746d501c41536ba40cd9c0a07d6a87" "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy/zipball/67a759e7d8746d501c41536ba40cd9c0a07d6a87", "url": "https://api.github.com/repos/phpspec/prophecy/zipball/a0165c648cab6a80311c74ffc708a07bb53ecc93",
"reference": "67a759e7d8746d501c41536ba40cd9c0a07d6a87", "reference": "a0165c648cab6a80311c74ffc708a07bb53ecc93",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"doctrine/instantiator": "^1.2 || ^2.0", "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", "phpdocumentor/reflection-docblock": "^5.2",
"sebastian/comparator": "^3.0 || ^4.0 || ^5.0 || ^6.0", "sebastian/comparator": "^3.0 || ^4.0 || ^5.0 || ^6.0",
"sebastian/recursion-context": "^3.0 || ^4.0 || ^5.0 || ^6.0" "sebastian/recursion-context": "^3.0 || ^4.0 || ^5.0 || ^6.0"
}, },
"require-dev": { "require-dev": {
"friendsofphp/php-cs-fixer": "^3.40",
"phpspec/phpspec": "^6.0 || ^7.0", "phpspec/phpspec": "^6.0 || ^7.0",
"phpstan/phpstan": "^1.9", "phpstan/phpstan": "^1.9",
"phpunit/phpunit": "^8.0 || ^9.0 || ^10.0" "phpunit/phpunit": "^8.0 || ^9.0 || ^10.0"
@ -4684,22 +4685,22 @@
], ],
"support": { "support": {
"issues": "https://github.com/phpspec/prophecy/issues", "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", "name": "phpspec/prophecy-phpunit",
"version": "v2.2.0", "version": "v2.3.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpspec/prophecy-phpunit.git", "url": "https://github.com/phpspec/prophecy-phpunit.git",
"reference": "16e1247e139434bce0bac09848bc5c8d882940fc" "reference": "8819516c1b489ecee4c60db5f5432fac1ea8ac6f"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/16e1247e139434bce0bac09848bc5c8d882940fc", "url": "https://api.github.com/repos/phpspec/prophecy-phpunit/zipball/8819516c1b489ecee4c60db5f5432fac1ea8ac6f",
"reference": "16e1247e139434bce0bac09848bc5c8d882940fc", "reference": "8819516c1b489ecee4c60db5f5432fac1ea8ac6f",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -4707,6 +4708,9 @@
"phpspec/prophecy": "^1.18", "phpspec/prophecy": "^1.18",
"phpunit/phpunit": "^9.1 || ^10.1 || ^11.0" "phpunit/phpunit": "^9.1 || ^10.1 || ^11.0"
}, },
"require-dev": {
"phpstan/phpstan": "^1.10"
},
"type": "library", "type": "library",
"extra": { "extra": {
"branch-alias": { "branch-alias": {
@ -4736,9 +4740,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/phpspec/prophecy-phpunit/issues", "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", "name": "phpstan/phpdoc-parser",
@ -6244,12 +6248,12 @@
], ],
"aliases": [], "aliases": [],
"minimum-stability": "stable", "minimum-stability": "stable",
"stability-flags": {}, "stability-flags": [],
"prefer-stable": false, "prefer-stable": false,
"prefer-lowest": false, "prefer-lowest": false,
"platform": { "platform": {
"ext-pdo": "*" "ext-pdo": "*"
}, },
"platform-dev": {}, "platform-dev": [],
"plugin-api-version": "2.6.0" "plugin-api-version": "2.6.0"
} }

View File

@ -0,0 +1,25 @@
<?php
declare(strict_types=1);
use Phinx\Migration\AbstractMigration;
final class AddTimeStampsToUsers extends AbstractMigration
{
/**
* Change Method.
*
* Write your reversible migrations using this method.
*
* More information on writing migrations is available here:
* https://book.cakephp.org/phinx/0/en/migrations.html#the-change-method
*
* Remember to call "create()" or "update()" and NOT "save()" when working
* with the Table class.
*/
public function change(): void
{
$table = $this->table("users")->addTimestamps();
$table->update();
}
}

View File

@ -58,6 +58,19 @@ abstract class Controller
->withHeader('Content-Type', 'text/html'); ->withHeader('Content-Type', 'text/html');
} }
/**
* Redirect helper for sending the client elsewhere.
*
* @param string $route The route to redirect doe
* @param int $code Default `301`, the code to respond with
*/
public function redirect(string $route, int $code = 301): Response
{
return $this->response
->withHeader('Location', $route)
->withStatus($code);
}
/** /**
* @param string $html The raw Twig HTML to render * @param string $html The raw Twig HTML to render
* @param array $data The data to injext into the HTML * @param array $data The data to injext into the HTML

View File

@ -29,12 +29,12 @@ class LoginUserAction extends Controller
} }
if (!$this->auth->verify($credentials['password'], $user->getPassword())) { if (!$this->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); return $this->render('user/login.twig')->withStatus(400);
} }
// start the session // start the session
$this->session->set('user', [ 'id' => $user->getId(), 'authenticated' => true ]); $this->session->set('user', [ 'id' => $user->getId(), 'authenticated' => true ]);
return $this->render('dashboard.twig', [ 'logged_in' => true ]); return $this->redirect('/dashboard', 302);
} }
} }

View File

@ -69,14 +69,14 @@ class UserRepository implements UserRepositoryInterface
*/ */
public function getFromEmail(string $email): User 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 ]); $results = $this->db->query($query, [ ':email' => $email ]);
if (!is_array($results) || empty($results)) { if (!is_array($results) || empty($results)) {
throw new EntityNotFoundException("Unable to find User"); throw new EntityNotFoundException("Unable to find User");
} }
return $this->userFromQueryResults($results); return $this->userFromQueryResults(array_shift($results));
} }
public function create(User $user): bool public function create(User $user): bool

View File

@ -7,7 +7,7 @@ use PDO;
class DatabaseHandler implements DatabaseHandlerInterface class DatabaseHandler implements DatabaseHandlerInterface
{ {
private PDO $pdo; private PDO $handle;
public function __construct( public function __construct(
private string $host, private string $host,
@ -16,7 +16,7 @@ class DatabaseHandler implements DatabaseHandlerInterface
private string $database, private string $database,
private int $port = 3306 private int $port = 3306
) { ) {
$this->pdo = new PDO( $this->handle = new PDO(
$this->getConnectionString(), $this->getConnectionString(),
$username, $username,
$password $password
@ -28,7 +28,7 @@ class DatabaseHandler implements DatabaseHandlerInterface
*/ */
public function getConnection() public function getConnection()
{ {
return $this->pdo; return $this->handle;
} }
public function getConnectionString(): string public function getConnectionString(): string
@ -48,14 +48,14 @@ class DatabaseHandler implements DatabaseHandlerInterface
public function query(string $query, array $params = []): array public function query(string $query, array $params = []): array
{ {
$statement = $this->database->prepare($query); $statement = $this->handle->prepare($query);
$statement->execute($params); $statement->execute($params);
return $statement->fetchAll($params); return $statement->fetchAll(PDO::FETCH_ASSOC);
} }
public function execute(string $query, array $params = []): bool public function execute(string $query, array $params = []): bool
{ {
$statement = $this->database->prepare($query); $statement = $this->handle->prepare($query);
return $statement->execute($params); return $statement->execute($params);
} }
} }