diff --git a/app/src/Controller/Controller.php b/app/src/Controller/Controller.php index 7b61c2e..fb9b60b 100644 --- a/app/src/Controller/Controller.php +++ b/app/src/Controller/Controller.php @@ -6,6 +6,7 @@ use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Views\Twig; use Slim\Routing\RouteContext; +use Odan\Session\SessionInterface; abstract class Controller { diff --git a/app/src/Controller/DashboardPage.php b/app/src/Controller/DashboardPage.php index 2ce81e5..334339b 100644 --- a/app/src/Controller/DashboardPage.php +++ b/app/src/Controller/DashboardPage.php @@ -15,6 +15,9 @@ class DashboardPage extends Controller 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 ]); diff --git a/app/src/Controller/User/LoginUserAction.php b/app/src/Controller/User/LoginUserAction.php index 7735e83..f51ba54 100644 --- a/app/src/Controller/User/LoginUserAction.php +++ b/app/src/Controller/User/LoginUserAction.php @@ -34,6 +34,7 @@ class LoginUserAction extends Controller } // start the session + $this->session->getFlash()->add('success', "Successfully loggedin."); $this->session->set('user', [ 'id' => $user->getId(), 'authenticated' => true ]); return $this->redirect('/dashboard', 302); } diff --git a/app/src/Middleware/AuthenticatedMiddleware.php b/app/src/Middleware/AuthenticatedMiddleware.php index 816dbe3..cbfaba4 100644 --- a/app/src/Middleware/AuthenticatedMiddleware.php +++ b/app/src/Middleware/AuthenticatedMiddleware.php @@ -19,6 +19,7 @@ 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 new file mode 100644 index 0000000..142a6ea --- /dev/null +++ b/app/src/Middleware/SessionMiddleware.php @@ -0,0 +1,29 @@ +sessionManager->isStarted()) { + $this->sessionManager->start(); + } + + return $handler->handle($request); + } +} diff --git a/app/src/Middlewares.php b/app/src/Middlewares.php index 0cc8804..d4e7f18 100644 --- a/app/src/Middlewares.php +++ b/app/src/Middlewares.php @@ -10,6 +10,7 @@ use Psr\Container\NotFoundExceptionInterface; use Slim\App; use Slim\Views\Twig; use Slim\Views\TwigMiddleware; +use Slovocast\Middleare\SessionMiddleware; use Twig\Error\LoaderError; class Middlewares @@ -29,6 +30,11 @@ class Middlewares */ $config = $container->get('config'); + /** + * Global session start + */ + $app->add(SessionMiddleware::class); + // Twig $templateCache = false; $twig = Twig::create(APP_TEMPLATES_DIR, [ 'cache' => $templateCache ]);