- Added a new CSRF token verification Middleware.

- Added a new ActionLog middleware to catch every modifying request and save the changes made and the user who did.
- Added a new RequestLog to catch every request made whenever required.
This commit is contained in:
Dave Mc Nicoll committed 2026-10-22 15:03:18 +00:00
1 parent 9571c6a462
commit 4b86ac9e82
42 files changed
+1331 -148

No files matched your search

+15 -17
View File
@@ -2,6 +2,7 @@
namespace Lean\Api\Middleware;
use DI\Attribute\Inject;
use Laminas\Diactoros\Response\JsonResponse;
use Lean\Factory\HttpFactory;
use Picea\Ui\Method\FormHandler;
@@ -10,15 +11,12 @@ use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use Lean\Api\{Controller\Debug, Factory\DebugFormFactoryInterface, Form, Entity};
use Lean\Api\{Factory\LeanApiFormFactoryInterface, Form, Entity};
class ApiRenderer implements MiddlewareInterface {
public function __construct(
protected ContainerInterface $container,
# protected DebugFormFactoryInterface $debugFormFactory,
) {
}
#[Inject]
protected LeanApiFormFactoryInterface $leanApiFormFactory;
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler) : ResponseInterface
{
@@ -27,7 +25,7 @@ class ApiRenderer implements MiddlewareInterface {
}
catch(\Throwable $ex) {
if (static::awaitingJson($request)) {
$this->saveError($request, $ex);
# $this->saveError($request, $ex);
return HttpFactory::createJsonResponse([
'status' => 'failed',
@@ -36,6 +34,7 @@ class ApiRenderer implements MiddlewareInterface {
# 'error_id' => $errorId,
'message' => $ex->getMessage(),
] + (getenv('DEBUG') ? [
'type' => $ex::class,
'file' => $ex->getFile(),
'line' => $ex->getLine(),
'code' => $ex->getCode(),
@@ -66,17 +65,17 @@ class ApiRenderer implements MiddlewareInterface {
if ($debugFormFactory = $this->container->get(DebugFormFactoryInterface::class)) {
$request = $request->withMethod('PUT')->withParsedBody([]);
$context = $debugFormFactory->errorSaveContext($request);
$context = $this->leanApiFormFactory->errorSaveContext($request);
$context->sets([
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTrace(),
]);
$context->sets([
'message' => $exception->getMessage(),
'code' => $exception->getCode(),
'file' => $exception->getFile(),
'line' => $exception->getLine(),
'trace' => $exception->getTrace(),
]);
$form = $debugFormFactory->errorSave($entity = new Entity\Error());
$form = $this->leanApiFormFactory->errorSave($entity = new Entity\Error());
new FormHandler($request, $form, $context);
}
@@ -96,7 +95,6 @@ class ApiRenderer implements MiddlewareInterface {
$item = static::encodeHtml($item);
}
elseif (is_string($item)) {
dump($item);
$item = htmlspecialchars($item);
}
}