From 89a6d50e5ff727524021fb006476ca47959de0c4 Mon Sep 17 00:00:00 2001 From: Dave Smith-Hayes Date: Sun, 24 Nov 2024 21:35:34 -0500 Subject: [PATCH] Test logging in and get all the names and typos worked out for getting sessions working. --- app/src/Bootstrap.php | 4 ++++ app/src/Controller/DashboardPage.php | 11 ++++++----- .../Repository/Channel/ChannelRepositoryInterface.php | 2 +- app/src/Middleware/AuthenticatedMiddleware.php | 1 - app/src/Middleware/SessionMiddleware.php | 2 +- app/src/Middlewares.php | 2 +- app/templates/layouts/skeleton.twig | 3 ++- 7 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/src/Bootstrap.php b/app/src/Bootstrap.php index eb01175..d95d1e0 100644 --- a/app/src/Bootstrap.php +++ b/app/src/Bootstrap.php @@ -26,6 +26,7 @@ use Psr\Log\LoggerInterface; use Slim\App; use Slim\Factory\AppFactory; use Slim\Psr7\Factory\ResponseFactory; +use Slovocast\Middleware\SessionMiddleware; use Twig\Error\LoaderError; use Slovocast\Configuration\DatabaseConnectionSchema; @@ -130,6 +131,9 @@ class Bootstrap 'flash' => function (ContainerInterface $container) { return $container->get(SessionInterface::class)->getFlash(); }, + SessionMiddleware::class => function (ContainerInterface $container) { + return new SessionMiddleware($container->get(SessionManagerInterface::class)); + }, /** * Application DI diff --git a/app/src/Controller/DashboardPage.php b/app/src/Controller/DashboardPage.php index 334339b..664ad85 100644 --- a/app/src/Controller/DashboardPage.php +++ b/app/src/Controller/DashboardPage.php @@ -2,6 +2,7 @@ namespace Slovocast\Controller; +use Odan\Session\SessionInterface; use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface; use Slovocast\Domain\Repository\User\UserRepositoryInterface; use Psr\Http\Message\ResponseInterface as Response; @@ -10,16 +11,16 @@ class DashboardPage extends Controller { public function __construct( protected UserRepositoryInterface $userRepository, - protected ChannelRepositoryInterface $channelRepository + protected ChannelRepositoryInterface $channelRepository, + protected SessionInterface $session ) { } public function handle(): Response { - if (!$this->session->has("logged_in")) { - - } // get the user details // get the channels - return $this->render('dashboard.twig', [ 'session' => $this->session ]); + return $this->render('dashboard.twig', [ + 'user' => $this->session->get('user'), + ]); } } diff --git a/app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php b/app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php index b54bb79..8f9825c 100644 --- a/app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php +++ b/app/src/Domain/Repository/Channel/ChannelRepositoryInterface.php @@ -10,7 +10,7 @@ interface ChannelRepositoryInterface public function get(int $id): Channel; public function getFromUser(User $user): Channel; public function getFromSlug(string $slug): Channel; - public function create(Channel $channel, User $user): int; + public function create(Channel $channel, User $user): Channel; public function update(Channel $channel): bool; public function delete(Channel $channel): bool; } diff --git a/app/src/Middleware/AuthenticatedMiddleware.php b/app/src/Middleware/AuthenticatedMiddleware.php index cbfaba4..816dbe3 100644 --- a/app/src/Middleware/AuthenticatedMiddleware.php +++ b/app/src/Middleware/AuthenticatedMiddleware.php @@ -19,7 +19,6 @@ class AuthenticatedMiddleware implements MiddlewareInterface public function process(Request $request, RequestHandler $handler): Response { if ($this->session->has('user')) { - dd($this->session->get('user')); if ($this->session->get('user')['authenticated']) { return $handler->handle($request); } diff --git a/app/src/Middleware/SessionMiddleware.php b/app/src/Middleware/SessionMiddleware.php index 142a6ea..2f37e71 100644 --- a/app/src/Middleware/SessionMiddleware.php +++ b/app/src/Middleware/SessionMiddleware.php @@ -1,6 +1,6 @@