- WIP on adding of HttpFactory and work on authorization from Ulmus/User too

This commit is contained in:
Dave M. 2023-11-03 19:51:39 -04:00
parent 1241e188e9
commit 16cd95abe2
9 changed files with 47 additions and 55 deletions

View File

@ -1,17 +1,46 @@
<?php
use Lean\Factory\HttpFactory;
use \Ulmus\User\Middleware\AuthorizeMiddleware;
use Ulmus\User\{Entity,
Lib\Authenticate,
Middleware\HeaderAuthenticationMiddleware,
Middleware\PostRequestAuthenticationMiddleware,
Authorize\PostRequestAuthentication};
use Picea\Picea;
use Storage\{ Cookie, Session };
use function DI\{get, autowire, create};
return [
AuthorizeMiddleware::class => create(AuthorizeMiddleware::class)->constructor(get('authorize.error')),
Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')),
HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authorize.error')),
PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor(get(\Ulmus\User\Lib\Authenticate::class), "email", "email", "password"),
PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(PostRequestAuthentication::class)),
'authentication.method' => null,
'authorize.error' => function($c) {
return HttpFactory::createJsonResponse([
'api.error' => "Authorization failed",
'api.datetime' => ( new \DateTime )->format(\DateTime::ATOM),
]);
return function(array $errorData) {
return HttpFactory::createJsonResponse($errorData + [
'api.error' => "Authorization failed",
'api.datetime' => (new \DateTime)->format(\DateTime::ATOM),
]);
};
},
'authentication.error' => function($c, Picea $picea) {
return function($message) use ($picea) {
return HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/500', [
'title' => "Authentication failed",
'subtitle' => "",
'message' => $message,
]));
};
},
];

View File

@ -8,7 +8,7 @@ use Mcnd\CLI\CliMiddleware;
use Notes\CLI\CommandFetcher;
use Lean\Lean;
use Lean\{ Factory, Lean };
return [
CommandFetcher::class => function($c) {
@ -27,7 +27,7 @@ return [
'cli.response:default' => function($c) {
return function() {
return new \Laminas\Diactoros\Response\TextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n");
return Factory\HttpFactory::createTextResponse("This is the default response from CLI middleware which indicates that no command were registered for this application.\n");
};
},
];

View File

@ -2,19 +2,17 @@
use function DI\autowire, DI\create, DI\get;
use Laminas\Diactoros\Response\HtmlResponse;
use Cronard\CronardMiddleware,
Notes\Cronard\TaskFetcher;
use Psr\Http\Message\ResponseInterface;
use Lean\Lean;
use Lean\{ Factory, Lean };
return [
CronardMiddleware::class => function($c) {
$cronardMiddleware = new CronardMiddleware($c, getenv('CRON_KEY'), function() : ResponseInterface {
return new HtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
return Factory\HttpFactory::createHtmlResponse(sprintf("%s - cron task begin...", date('Y-m-d H:i:s')));
}, []);
return $cronardMiddleware->fromFile(getenv("META_PATH")."/crontab.php")->fromAnnotations($c->get(TaskFetcher::class));

View File

@ -26,7 +26,7 @@ return [
Event\EventDefinition::class => function($c) {
return new Event\EventDefinition([
new class() implements RoutingCompileRoutes {
public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void
public function execute(Routing $routing, Route $attribute) : void
{
if (null !== ($name = $attribute->name ?? null)) {
$routing->extension->registerRoute($name, $attribute->getRoute(), $attribute->class, $attribute->classMethod, $attribute->methods ?? (array)$attribute->method);
@ -35,7 +35,7 @@ return [
},
new class() implements RoutingMapRoutes {
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void
{
$class = $attribute->class;
$method = $attribute->classMethod;

View File

@ -3,29 +3,16 @@
use function DI\autowire, DI\create, DI\get;
use League\Route\Strategy\ApplicationStrategy,
League\Route\Http\Exception\NotFoundException,
League\Route\Router;
use Psr\Http\Message\ResponseFactoryInterface,
Psr\Container\ContainerInterface,
Psr\Http\Message\ResponseInterface,
Psr\Http\Message\ServerRequestInterface,
Psr\Http\Server\MiddlewareInterface,
Psr\Http\Server\RequestHandlerInterface,
Psr\SimpleCache\CacheInterface;
use TheBugs\JavascriptMiddleware;
use Psr\Container\ContainerInterface;
use Cronard\CronardMiddleware;
use Tuupola\Middleware\HttpBasicAuthentication;
use Notes\Route\RouteFetcher;
use Notes\Breadcrumb\Breadcrumb;
use Ulmus\User\Lib\Authenticate;
use Storage\SessionMiddleware;
return [

View File

@ -2,18 +2,10 @@
use function DI\autowire, DI\create, DI\get;
use Laminas\Diactoros\Response\HtmlResponse;
use TheBugs\JavascriptMiddleware;
use Cronard\CronardMiddleware,
Notes\Cronard\TaskFetcher;
use Lean\Lean;
use Psr\Http\Message\ResponseInterface;
use Storage\Cookie,
Storage\Session,
Storage\SessionMiddleware;

View File

@ -22,29 +22,15 @@ use TheBugs\Email\{ EmailConfiguration, MailerInterface, SwiftMailer };
use Taxus\{ Taxus, PermissionGrantInterface };
return [
Entity\User::class => autowire(Entity\User::class),
Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')),
\Ulmus\User\Entity\UserInterface::class => autowire(Entity\User::class),
SecurityHandler::class => create(SecurityHandler::class)->constructor(function() {
return new RedirectResponse(getenv("URL_BASE")."/login");
return Lean\Factory\HttpFactory::createRedirectResponse(getenv("URL_BASE")."/login");
}, get('authentication.unauthorize'), get(Taxus::class)),
'authentication.method' => null,
'authentication.error' => function($c, Picea $picea) {
return function($message) use ($picea) {
return new HtmlResponse($picea->renderHtml('lean/error/500', [
'title' => "",
'subtitle' => "",
'message' => $message,
]));
};
},
'authentication.unauthorize' => function($c, Picea $picea) {
return function($message) use ($picea) {
return new HtmlResponse($picea->renderHtml('lean/error/401', [
return Lean\Factory\HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/401', [
'title' => "",
'subtitle' => "",
'message' => $message,

View File

@ -6,5 +6,5 @@ use Lean\Routing;
use Notes\Route\Attribute\Method\Route;
interface RoutingCompileRoutes {
public function execute(Routing $routing, Route|\Notes\Route\Annotation\Method\Route $attribute) : void;
public function execute(Routing $routing, Route $attribute) : void;
}

View File

@ -8,5 +8,5 @@ use Psr\Container\ContainerInterface;
use Psr\Http\Message\{ ResponseInterface, ServerRequestInterface };
interface RoutingMapRoutes {
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route|\Notes\Route\Annotation\Method\Route $attribute) : void;
public function execute(Routing $routing, ContainerInterface $container, ServerRequestInterface & $request, Route $attribute) : void;
}