Add middleware conforming to the PSR interfaces

This commit is contained in:
Dave Smith-Hayes 2024-06-15 22:32:31 -04:00
parent f0c91e5aaa
commit 61081ac65c

View File

@ -0,0 +1,33 @@
<?php
namespace Slovocast\Middleware;
use Odan\Session\SessionInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface as RequestHandler;
use Psr\Http\Message\ServerRequestInterface as Request;
use Psr\Http\Message\ResponseInterface as Response;
class VerifyPasswordMiddleware implements MiddlewareInterface
{
public function __construct(
private SessionInterface $session
) {}
public function process(Request $request, RequestHandler $handler): Response
{
// get user Data
$requestData = $request->getParsedBody();
if ($requestData['password'] !== $requestData['checked_password']) {
$this->session
->getFlash()
->add('error', "Passwords do not match.");
$response = $handler->handle($request);
return $response->withStatus(400);
}
return $handler->handle($request);
}
}