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 @@