Compare commits

..

2 Commits

Author SHA1 Message Date
Dave Mc Nicoll
1c2ce07179 - Fixed merges of latest master 2025-06-13 19:25:08 +00:00
Dave Mc Nicoll
af8b686e3b - WIP on ulmus-user mechanics updates 2025-06-13 19:14:30 +00:00
19 changed files with 71 additions and 172 deletions

View File

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

View File

@ -1,11 +1,15 @@
<?php <?php
use Lean\ApplicationStrategy\{ ThrowableHandler, ThrowableHandlerInterface, NotFoundDecoratorInterface, NotFoundDecorator, MethodNotAllowedInterface, }; use Psr\Container\ContainerInterface;
use function DI\autowire, DI\create, DI\get;
use Lean\ApplicationStrategy\{ ThrowableHandler, ThrowableHandlerInterface, NotFoundDecoratorInterface, NotFoundDecorator };
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Laminas\{ Diactoros\ServerRequestFactory, HttpHandlerRunner\Emitter\EmitterInterface, HttpHandlerRunner\Emitter\SapiEmitter }; use Laminas\{ Diactoros\ServerRequestFactory, HttpHandlerRunner\Emitter\EmitterInterface, HttpHandlerRunner\Emitter\SapiEmitter };
use Lean\Factory\{ HttpFactory, HttpFactoryInterface };
use Picea\Picea;
use function DI\autowire, DI\create, DI\get;
return [ return [
ServerRequestInterface::class => function ($c) { ServerRequestInterface::class => function ($c) {
@ -15,7 +19,21 @@ return [
}, },
EmitterInterface::class => create(SapiEmitter::class), EmitterInterface::class => create(SapiEmitter::class),
HttpFactoryInterface::class => create(HttpFactory::class),
'error.401' => function(ContainerInterface $c, Picea $picea) {
return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/401", []), 401);
},
'error.404' => function(ContainerInterface $c, Picea $picea) {
return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/404", []), 404);
},
'error.500' => function(ContainerInterface $c, Picea $picea) {
return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/500", []), 500);
},
ThrowableHandlerInterface::class => autowire(ThrowableHandler::class), ThrowableHandlerInterface::class => autowire(ThrowableHandler::class),
NotFoundDecoratorInterface::class => autowire(NotFoundDecorator::class), NotFoundDecoratorInterface::class => autowire(NotFoundDecorator::class),
# MethodNotAllowedInterface::class => autowire(MethodNotAllowedDecorator::class),
]; ];

View File

@ -5,15 +5,6 @@
"week": "week" "week": "week"
}, },
"interval": {
"years": "{$years} year(s)",
"months": "{$months} month(s)",
"days": "{$days} day(s)",
"hours": "{$hours} hour(s)",
"minutes": "{$minutes} minutes(s)",
"seconds": "{$seconds} second(s)"
},
"month": { "month": {
"list": [ "list": [
"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Décember" "January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "Décember"

View File

@ -4,15 +4,6 @@
"week": "semaine" "week": "semaine"
}, },
"interval": {
"years": "{$years} années(s)",
"months": "{$months} mois",
"days": "{$days} jour(s)",
"hours": "{$hours} heure(s)",
"minutes": "{$minutes} minutes(s)",
"seconds": "{$seconds} seconde(s)"
},
"month": { "month": {
"list": [ "list": [
"Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre" "Janvier", "Février", "Mars", "Avril", "Mai", "Juin", "Juillet", "Août", "Septembre", "Octobre", "Novembre", "Décembre"

0
skeleton/lean Executable file → Normal file
View File

View File

@ -4,6 +4,7 @@ use function DI\autowire, DI\create, DI\get;
use %NAMESPACE%\Entity; use %NAMESPACE%\Entity;
use Psr\Container\ContainerInterface;
use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Message\ServerRequestInterface;
use Ulmus\Entity\Field\Datetime, use Ulmus\Entity\Field\Datetime,
@ -21,16 +22,18 @@ use TheBugs\Email\{ EmailConfiguration, MailerInterface, SwiftMailer };
use Taxus\{ Taxus, PermissionGrantInterface }; use Taxus\{ Taxus, PermissionGrantInterface };
use Lean\Factory\HttpFactoryInterface;
return [ return [
\Ulmus\User\Entity\UserInterface::class => autowire(Entity\User::class), \Ulmus\User\Entity\UserInterface::class => autowire(Entity\User::class),
SecurityHandler::class => create(SecurityHandler::class)->constructor(function() { SecurityHandler::class => create(SecurityHandler::class)->constructor(function(ContainerInterface $c) {
return Lean\Factory\HttpFactory::createRedirectResponse(getenv("URL_BASE")."/login"); return $c->get(HttpFactoryInterface::class)::createRedirectResponse(getenv("URL_BASE")."/login");
}, get('authentication.unauthorize'), get(Taxus::class)), }, get('authentication.unauthorize'), get(Taxus::class)),
'authentication.unauthorize' => function($c, Picea $picea) { 'authentication.unauthorize' => function(ContainerInterface $c, Picea $picea) {
return function($message) use ($picea) { return function($message) use ($c, $picea) {
return Lean\Factory\HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/401', [ return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml('lean/error/401', [
'title' => "", 'title' => "",
'subtitle' => "", 'subtitle' => "",
'message' => $message, 'message' => $message,

View File

@ -7,10 +7,6 @@ use function DI\{ autowire, add, create, get };
$dir = dirname(__DIR__, 2); $dir = dirname(__DIR__, 2);
return [ return [
\%NAMESPACE%\Factory\FormFactoryInterface::class => autowire(\%NAMESPACE%\Factory\FormFactory::class),
\Lean\Api\Factory\MessageFactoryInterface::class => autowire(\%NAMESPACE%\Lib\Message::class),
'%APPKEY%' => [ '%APPKEY%' => [
'picea' => [ 'picea' => [
'context' => "%ESCAPED_NAMESPACE%\\View", 'context' => "%ESCAPED_NAMESPACE%\\View",

View File

@ -4,7 +4,7 @@ use Picea\Picea;
use Negundo\Client\{ NegundoMiddleware, SoftwareConfig }; use Negundo\Client\{ NegundoMiddleware, SoftwareConfig };
use Lean\Factory\HttpFactory; use Lean\Factory\HttpFactoryInterface;
use Psr\Http\Server\MiddlewareInterface, use Psr\Http\Server\MiddlewareInterface,
Psr\Http\Message\ServerRequestInterface, Psr\Http\Message\ServerRequestInterface,
@ -31,11 +31,11 @@ return [
"errorHandler" => create(NegundoMiddleware::class)->constructor(get(SoftwareConfig::class), null, get('app.errorhandler.html')), "errorHandler" => create(NegundoMiddleware::class)->constructor(get(SoftwareConfig::class), null, get('app.errorhandler.html')),
'app.errorhandler.html' => function($c, Picea $picea) { 'app.errorhandler.html' => function(\Psr\Container\ContainerInterface $c, Picea $picea) {
return function(\Throwable $exception) use ($picea) { return function(\Throwable $exception) use ($c, $picea) {
error_log($exception->getMessage()); error_log($exception->getMessage());
return HttpFactory::createHtmlResponse($picea->renderHtml('lean/error/500', [ return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml('lean/error/500', [
'title' => "Une erreur s'est produite lors de l'exécution du script.", 'title' => "Une erreur s'est produite lors de l'exécution du script.",
'subtitle' => "Êtes-vous connecté avec le bon compte ?", 'subtitle' => "Êtes-vous connecté avec le bon compte ?",
'message' => $exception->getMessage(), 'message' => $exception->getMessage(),

View File

@ -1,46 +0,0 @@
<?php
namespace %NAMESPACE%\Factory;
use Lean\Api\Factory\MessageFactoryInterface;
use Lean\LanguageHandler;
use Picea\Ui\Method\FormContextInterface;
use Picea\Ui\Method\FormInterface;
use Psr\Http\Message\ServerRequestInterface;
use Storage\Session;
use Ulmus\Entity\EntityInterface;
use Ulmus\User\Entity\UserInterface;
use Ulmus\User\Lib\Authenticate;
class FormFactory implements FormFactoryInterface
{
/*
public function __construct(
protected ServerRequestInterface $request,
protected Authenticate $authenticate,
protected Session $session,
protected LanguageHandler $languageHandler,
protected MessageFactoryInterface $messageFactory,
) {}
public function save(EntityInterface $entity): FormInterface
{
return new Form\Save($this->languageHandler, $this->messageFactory, $entity);
}
public function saveContext(? ServerRequestInterface $request = null, ? string $formName = null): FormContextInterface
{
return new Form\SaveContext($request ?: $this->request, $formName);
}
public function delete(EntityInterface $entity): FormInterface
{
return new Form\Delete($this->languageHandler, $this->messageFactory, $entity);
}
public function deleteContext(?ServerRequestInterface $request = null, ?string $formName = null): FormContextInterface
{
return new Lib\FormContext($request, $formName);
}
*/
}

View File

@ -1,25 +0,0 @@
<?php
namespace %NAMESPACE%\Factory;
use Lean\Api\Factory\MessageFactoryInterface;
use Psr\Http\Message\ServerRequestInterface;
use Picea\Ui\Method\{ FormInterface, FormContextInterface };
use Storage\Session;
use Lean\LanguageHandler;
use Ulmus\Entity\EntityInterface;
use Ulmus\User\Entity\UserInterface;
use Ulmus\User\Lib\Authenticate;
interface FormFactoryInterface
{
/* public function __construct(ServerRequestInterface $request, Authenticate $authenticate, Session $session, LanguageHandler $languageHandler, MessageFactoryInterface $messageFactory,);
public function save(EntityInterface $entity): FormInterface;
public function saveContext(?ServerRequestInterface $request = null, ?string $formName = null): FormContextInterface;
public function delete(EntityInterface $entity): FormInterface;
public function deleteContext(?ServerRequestInterface $request = null, ?string $formName = null): FormContextInterface;*/
}

View File

@ -2,10 +2,8 @@
namespace Lean; namespace Lean;
use League\Route\Http\Exception\MethodNotAllowedException;
use League\Route\Strategy; use League\Route\Strategy;
use League\Route\Http\Exception\NotFoundException; use League\Route\Http\Exception\NotFoundException;
use Lean\ApplicationStrategy\MethodNotAllowedInterface;
use Lean\ApplicationStrategy\NotFoundDecoratorInterface; use Lean\ApplicationStrategy\NotFoundDecoratorInterface;
use Lean\ApplicationStrategy\ThrowableHandlerInterface; use Lean\ApplicationStrategy\ThrowableHandlerInterface;
use Lean\Factory\HttpFactoryInterface; use Lean\Factory\HttpFactoryInterface;
@ -32,10 +30,6 @@ class ApplicationStrategy extends Strategy\ApplicationStrategy {
public function getThrowableHandler(): MiddlewareInterface public function getThrowableHandler(): MiddlewareInterface
{ {
return $this->getContainer()->get(ThrowableHandlerInterface::class); return $this->getContainer()->get(ThrowableHandlerInterface::class);
}
public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception): MiddlewareInterface
{
return $this->getContainer()->has(MethodNotAllowedInterface::class) ? $this->getContainer()->get(MethodNotAllowedInterface::class) : parent::getMethodNotAllowedDecorator($exception);
} }
} }

View File

@ -1,10 +0,0 @@
<?php
namespace Lean\ApplicationStrategy;
use Psr\Http\Server\MiddlewareInterface;
interface MethodNotAllowedInterface extends MiddlewareInterface
{
}

View File

@ -34,7 +34,7 @@ class NotFoundDecorator implements NotFoundDecoratorInterface
return $this->throw404($request); return $this->throw404($request);
} }
return $handler->handle($request);; return $handler->handle($request);
} }
public function throw404(ServerRequestInterface $request) : ResponseInterface public function throw404(ServerRequestInterface $request) : ResponseInterface

View File

@ -8,7 +8,6 @@ use Notes\Attribute\Ignore;
use Notes\Route\Attribute\Object\Route; use Notes\Route\Attribute\Object\Route;
use Notes\Security\Attribute\Security; use Notes\Security\Attribute\Security;
use Picea, Picea\Ui\Method\FormContext; use Picea, Picea\Ui\Method\FormContext;
use Picea\Ui\Method\FormContextInterface;
use TheBugs\Email\MailerInterface; use TheBugs\Email\MailerInterface;
use Storage\{ Cookie, Session }; use Storage\{ Cookie, Session };
use League\CommonMark\CommonMarkConverter; use League\CommonMark\CommonMarkConverter;
@ -213,7 +212,7 @@ trait ControllerTrait {
} }
#[Ignore] #[Ignore]
public function pushContext(FormContextInterface $context) : FormContextInterface public function pushContext(FormContext $context) : FormContext
{ {
$this->contextList[$context->formName ?? uniqid("context_")] = $context; $this->contextList[$context->formName ?? uniqid("context_")] = $context;
@ -221,7 +220,7 @@ trait ControllerTrait {
} }
#[Ignore] #[Ignore]
public function context(? string $name = null) : ? FormContextInterface public function context(? string $name = null) : ? FormContext
{ {
return $name ? $this->contextList[$name] : array_values($this->contextList)[0] ?? null; return $name ? $this->contextList[$name] : array_values($this->contextList)[0] ?? null;
} }

View File

@ -2,9 +2,6 @@
namespace Lean\Factory; namespace Lean\Factory;
use Laminas\Diactoros\Response\{EmptyResponse, HtmlResponse, JsonResponse, RedirectResponse, TextResponse};
use Lean\Response\{ DownloadResponse, ImageResponse, FileDownloadResponse, PdfResponse };
use Laminas\Diactoros\Response;
use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ResponseInterface;
interface HttpFactoryInterface interface HttpFactoryInterface

View File

@ -27,15 +27,18 @@ class Kernel {
public array $paths = []; public array $paths = [];
public int $errorReporting = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_NOTICE; public int $errorReporting = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED & ~E_STRICT & ~E_NOTICE;
public array $definitionFilePaths; public array $definitionFilePaths;
public string $errorLogPath; public string $errorLogPath;
public function __construct( public string $projectPath;
public string $projectPath
) { public function __construct(string $projectPath)
{
$this->projectPath = $projectPath;
$this->setEnvironment(); $this->setEnvironment();
$this->initializeEngine(); $this->initializeEngine();
$this->setupContainer(); $this->setupContainer();

View File

@ -1,23 +0,0 @@
{% arguments \DateInterval $interval %}
{% if $interval->y %}
{% lang "lean.date.interval.years", [ 'years' => $interval->y ] %},
{% endif %}
{% if $interval->m %}
{% lang "lean.date.interval.months", [ 'months' => $interval->m ] %},
{% endif %}
{% if $interval->d %}
{% lang "lean.date.interval.days", [ 'days' => $interval->d ] %},
{% endif %}
{% if $interval->h %}
{% lang "lean.date.interval.hours", [ 'hours' => $interval->h ] %},
{% endif %}
{% if $interval->i %}
{% lang "lean.date.interval.minutes", [ 'minutes' => $interval->i ] %}
{% else %}
{% lang "lean.date.interval.seconds", [ 'seconds' => $interval->s ] %}
{% endif %}

File diff suppressed because one or more lines are too long

Before

Width:  |  Height:  |  Size: 32 KiB

After

Width:  |  Height:  |  Size: 40 KiB