Add a dashboard controller.

This commit is contained in:
Dave Smith-Hayes 2024-06-27 19:50:42 -04:00
parent 19222f0cf9
commit 037cf674a8
3 changed files with 44 additions and 14 deletions

View File

@ -0,0 +1,19 @@
<?php
namespace Slovocast\Controller;
use Slovocast\Controller\Controller;
use Slovocast\Domain\Repository\User\UserRepositoryInterface;
use Psr\Http\Message\ResponseInterface as Response;
class DashboardPage extends Controller
{
public function __construct(
protected UserRepositoryInterface $userRepository
) { }
public function handle(): Response
{
return $this->render('dashboard.twig');
}
}

View File

@ -18,11 +18,13 @@ class AuthenticatedMiddleware implements MiddlewareInterface
public function process(Request $request, RequestHandler $handler): Response
{
if (!this->session->has('user')) {
$response = $this->responseFactory->createResponse(403, "Unauthorized");
return $response;
if ($this->session->has('user')) {
if ($this->session->get('user')['authenticated']) {
return $handler->handle($request);
}
}
return $handler->handle($request);
$response = $this->responseFactory->createResponse(403, "Unauthorized");
return $response;
}
}

View File

@ -5,19 +5,20 @@ namespace Slovocast;
use Slim\App;
use Slovocast\Controller\HomePage;
use Slovocast\Controller\HealthCheck;
use Slovocast\Controller\User\{
RegisterUserPage,
RegisterUserAction,
LoginUserPage,
LoginUserAction
};
use Slovocast\Middleware\{
VerifyPasswordMiddleware,
AuthenticatedMiddleware
};
use Slovocast\Controller\DashboardPage;
use Slovocast\Controller\User\RegisterUserPage;
use Slovocast\Controller\User\RegisterUserAction;
use Slovocast\Controller\User\LoginUserPage;
use Slovocast\Controller\User\LoginUserAction;
use Slovocast\Middleware\VerifyPasswordMiddleware;
use Slovocast\Middleware\AuthenticatedMiddleware;
class Routes
{
/**
* @param App $app Instantiated Application
* @return void
*/
public static function init(App $app): void
{
$app->get('/', HomePage::class);
@ -26,6 +27,10 @@ class Routes
self::users($app);
}
/**
* @param App $app Instantiated Application
* @return void
*/
protected static function users(App $app): void
{
$app->get('/users/register', RegisterUserPage::class)
@ -39,5 +44,9 @@ class Routes
$app->post('/login', LoginUserAction::class)
->add(AuthenticatedMiddleware::class)
->setName('user-login-action');
$app->get('/dashboard', DashboardPage::class)
->add(AuthenticatedMiddleware::class)
->setName('user-dashboard');
}
}