Add middleware conforming to the PSR interfaces
This commit is contained in:
parent
f0c91e5aaa
commit
61081ac65c
33
app/src/Middleware/VerifyPasswordMiddleware.php
Normal file
33
app/src/Middleware/VerifyPasswordMiddleware.php
Normal 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);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user