Test logging in and get all the names and typos worked out for getting sessions working.
This commit is contained in:
parent
7b54952b55
commit
89a6d50e5f
@ -26,6 +26,7 @@ use Psr\Log\LoggerInterface;
|
|||||||
use Slim\App;
|
use Slim\App;
|
||||||
use Slim\Factory\AppFactory;
|
use Slim\Factory\AppFactory;
|
||||||
use Slim\Psr7\Factory\ResponseFactory;
|
use Slim\Psr7\Factory\ResponseFactory;
|
||||||
|
use Slovocast\Middleware\SessionMiddleware;
|
||||||
use Twig\Error\LoaderError;
|
use Twig\Error\LoaderError;
|
||||||
|
|
||||||
use Slovocast\Configuration\DatabaseConnectionSchema;
|
use Slovocast\Configuration\DatabaseConnectionSchema;
|
||||||
@ -130,6 +131,9 @@ class Bootstrap
|
|||||||
'flash' => function (ContainerInterface $container) {
|
'flash' => function (ContainerInterface $container) {
|
||||||
return $container->get(SessionInterface::class)->getFlash();
|
return $container->get(SessionInterface::class)->getFlash();
|
||||||
},
|
},
|
||||||
|
SessionMiddleware::class => function (ContainerInterface $container) {
|
||||||
|
return new SessionMiddleware($container->get(SessionManagerInterface::class));
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Application DI
|
* Application DI
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace Slovocast\Controller;
|
namespace Slovocast\Controller;
|
||||||
|
|
||||||
|
use Odan\Session\SessionInterface;
|
||||||
use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface;
|
use Slovocast\Domain\Repository\Channel\ChannelRepositoryInterface;
|
||||||
use Slovocast\Domain\Repository\User\UserRepositoryInterface;
|
use Slovocast\Domain\Repository\User\UserRepositoryInterface;
|
||||||
use Psr\Http\Message\ResponseInterface as Response;
|
use Psr\Http\Message\ResponseInterface as Response;
|
||||||
@ -10,16 +11,16 @@ class DashboardPage extends Controller
|
|||||||
{
|
{
|
||||||
public function __construct(
|
public function __construct(
|
||||||
protected UserRepositoryInterface $userRepository,
|
protected UserRepositoryInterface $userRepository,
|
||||||
protected ChannelRepositoryInterface $channelRepository
|
protected ChannelRepositoryInterface $channelRepository,
|
||||||
|
protected SessionInterface $session
|
||||||
) { }
|
) { }
|
||||||
|
|
||||||
public function handle(): Response
|
public function handle(): Response
|
||||||
{
|
{
|
||||||
if (!$this->session->has("logged_in")) {
|
|
||||||
|
|
||||||
}
|
|
||||||
// get the user details
|
// get the user details
|
||||||
// get the channels
|
// get the channels
|
||||||
return $this->render('dashboard.twig', [ 'session' => $this->session ]);
|
return $this->render('dashboard.twig', [
|
||||||
|
'user' => $this->session->get('user'),
|
||||||
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -10,7 +10,7 @@ interface ChannelRepositoryInterface
|
|||||||
public function get(int $id): Channel;
|
public function get(int $id): Channel;
|
||||||
public function getFromUser(User $user): Channel;
|
public function getFromUser(User $user): Channel;
|
||||||
public function getFromSlug(string $slug): 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 update(Channel $channel): bool;
|
||||||
public function delete(Channel $channel): bool;
|
public function delete(Channel $channel): bool;
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,6 @@ class AuthenticatedMiddleware implements MiddlewareInterface
|
|||||||
public function process(Request $request, RequestHandler $handler): Response
|
public function process(Request $request, RequestHandler $handler): Response
|
||||||
{
|
{
|
||||||
if ($this->session->has('user')) {
|
if ($this->session->has('user')) {
|
||||||
dd($this->session->get('user'));
|
|
||||||
if ($this->session->get('user')['authenticated']) {
|
if ($this->session->get('user')['authenticated']) {
|
||||||
return $handler->handle($request);
|
return $handler->handle($request);
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace Slovocast\Middleare;
|
namespace Slovocast\Middleware;
|
||||||
|
|
||||||
use Odan\Session\SessionManagerInterface;
|
use Odan\Session\SessionManagerInterface;
|
||||||
use Psr\Http\Server\MiddlewareInterface;
|
use Psr\Http\Server\MiddlewareInterface;
|
||||||
|
@ -10,7 +10,7 @@ use Psr\Container\NotFoundExceptionInterface;
|
|||||||
use Slim\App;
|
use Slim\App;
|
||||||
use Slim\Views\Twig;
|
use Slim\Views\Twig;
|
||||||
use Slim\Views\TwigMiddleware;
|
use Slim\Views\TwigMiddleware;
|
||||||
use Slovocast\Middleare\SessionMiddleware;
|
use Slovocast\Middleware\SessionMiddleware;
|
||||||
use Twig\Error\LoaderError;
|
use Twig\Error\LoaderError;
|
||||||
|
|
||||||
class Middlewares
|
class Middlewares
|
||||||
|
@ -19,8 +19,9 @@
|
|||||||
|
|
||||||
<nav>
|
<nav>
|
||||||
<ul>
|
<ul>
|
||||||
{% if logged_in %}
|
{% if user.authenticated %}
|
||||||
<li><a href="/dashboard">Dashboard</a></li>
|
<li><a href="/dashboard">Dashboard</a></li>
|
||||||
|
<li><a href="/logout">Logout</a></li>
|
||||||
{% else %}
|
{% else %}
|
||||||
<li><a href="/login">Login</a></li>
|
<li><a href="/login">Login</a></li>
|
||||||
<li><a href="/register">Register</a></li>
|
<li><a href="/register">Register</a></li>
|
||||||
|
Loading…
Reference in New Issue
Block a user