Test logging in and get all the names and typos worked out for getting sessions working.

This commit is contained in:
Dave Smith-Hayes 2024-11-24 21:35:34 -05:00
parent 7b54952b55
commit 89a6d50e5f
7 changed files with 15 additions and 10 deletions

View File

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

View File

@ -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'),
]);
}
}

View File

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

View File

@ -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);
}

View File

@ -1,6 +1,6 @@
<?php
namespace Slovocast\Middleare;
namespace Slovocast\Middleware;
use Odan\Session\SessionManagerInterface;
use Psr\Http\Server\MiddlewareInterface;

View File

@ -10,7 +10,7 @@ use Psr\Container\NotFoundExceptionInterface;
use Slim\App;
use Slim\Views\Twig;
use Slim\Views\TwigMiddleware;
use Slovocast\Middleare\SessionMiddleware;
use Slovocast\Middleware\SessionMiddleware;
use Twig\Error\LoaderError;
class Middlewares

View File

@ -19,8 +19,9 @@
<nav>
<ul>
{% if logged_in %}
{% if user.authenticated %}
<li><a href="/dashboard">Dashboard</a></li>
<li><a href="/logout">Logout</a></li>
{% else %}
<li><a href="/login">Login</a></li>
<li><a href="/register">Register</a></li>