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 public function process(Request $request, RequestHandler $handler): Response
{ {
if (!this->session->has('user')) { if ($this->session->has('user')) {
$response = $this->responseFactory->createResponse(403, "Unauthorized"); if ($this->session->get('user')['authenticated']) {
return $response;
}
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 Slim\App;
use Slovocast\Controller\HomePage; use Slovocast\Controller\HomePage;
use Slovocast\Controller\HealthCheck; use Slovocast\Controller\HealthCheck;
use Slovocast\Controller\User\{ use Slovocast\Controller\DashboardPage;
RegisterUserPage, use Slovocast\Controller\User\RegisterUserPage;
RegisterUserAction, use Slovocast\Controller\User\RegisterUserAction;
LoginUserPage, use Slovocast\Controller\User\LoginUserPage;
LoginUserAction use Slovocast\Controller\User\LoginUserAction;
}; use Slovocast\Middleware\VerifyPasswordMiddleware;
use Slovocast\Middleware\{ use Slovocast\Middleware\AuthenticatedMiddleware;
VerifyPasswordMiddleware,
AuthenticatedMiddleware
};
class Routes class Routes
{ {
/**
* @param App $app Instantiated Application
* @return void
*/
public static function init(App $app): void public static function init(App $app): void
{ {
$app->get('/', HomePage::class); $app->get('/', HomePage::class);
@ -26,6 +27,10 @@ class Routes
self::users($app); self::users($app);
} }
/**
* @param App $app Instantiated Application
* @return void
*/
protected static function users(App $app): void protected static function users(App $app): void
{ {
$app->get('/users/register', RegisterUserPage::class) $app->get('/users/register', RegisterUserPage::class)
@ -39,5 +44,9 @@ class Routes
$app->post('/login', LoginUserAction::class) $app->post('/login', LoginUserAction::class)
->add(AuthenticatedMiddleware::class) ->add(AuthenticatedMiddleware::class)
->setName('user-login-action'); ->setName('user-login-action');
$app->get('/dashboard', DashboardPage::class)
->add(AuthenticatedMiddleware::class)
->setName('user-dashboard');
} }
} }