- WIP on ulmus-user mechanics updates

This commit is contained in:
Dave Mc Nicoll committed 2026-10-19 19:55:28 +00:00
1 parent 064d94d32a
commit 50b17ec8b6
8 files changed
+83 -21

No files matched your search

+8 -8
View File
@@ -2,16 +2,16 @@
use Lean\Factory\HttpFactoryInterface; use Lean\Factory\HttpFactoryInterface;
use Ulmus\User\{Authorize\HeaderAuthentication, use Ulmus\User\{
Authorize\CookieAuthentication,
Authorize\HeaderAuthentication,
Entity, Entity,
Lib\Authenticate, Lib\Authenticate,
Lib\Authorize, Lib\Authorize,
Middleware\AuthenticationMiddleware, Middleware\AuthenticationMiddleware,
Middleware\HeaderAuthenticationMiddleware, Middleware\HeaderAuthenticationMiddleware,
Middleware\CookieAuthenticationMiddleware,
Middleware\PostRequestAuthenticationMiddleware, Middleware\PostRequestAuthenticationMiddleware,
Middleware\LocalMacAddressMiddleware,
Authorize\MacAddressAuthentication,
Authorize\PostRequestAuthentication}; Authorize\PostRequestAuthentication};
use Picea\Picea; use Picea\Picea;
@@ -32,14 +32,14 @@ return [
HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(HeaderAuthentication::class)), HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(HeaderAuthentication::class)),
CookieAuthentication::class => autowire(CookieAuthentication::class),
CookieAuthenticationMiddleware::class => create(CookieAuthenticationMiddleware::class)->constructor(get(CookieAuthentication::class), get(Cookie::class)),
PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor("email", "email", "password"), PostRequestAuthentication::class => create(PostRequestAuthentication::class)->constructor("email", "email", "password"),
PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(PostRequestAuthentication::class)), PostRequestAuthenticationMiddleware::class => create(PostRequestAuthenticationMiddleware::class)->constructor(get(PostRequestAuthentication::class)),
MacAddressAuthentication::class => create(MacAddressAuthentication::class)->constructor(get(Authenticate::class), "mac"),
LocalMacAddressMiddleware::class => create(LocalMacAddressMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authentication.error'), get(MacAddressAuthentication::class)),
'authentication.method' => null, 'authentication.method' => null,
'authorize.error' => function(ContainerInterface $c) { 'authorize.error' => function(ContainerInterface $c) {
+19
View File
@@ -6,6 +6,9 @@ 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 Lean\Factory\{ HttpFactory, HttpFactoryInterface };
use Picea\Picea; use Picea\Picea;
use Storage\Cookie,
Storage\Session,
Storage\SessionMiddleware;
use function DI\autowire, DI\create, DI\get; use function DI\autowire, DI\create, DI\get;
@@ -24,6 +27,22 @@ return [
HttpFactoryInterface::class => create(HttpFactory::class), HttpFactoryInterface::class => create(HttpFactory::class),
Cookie::class => create(Cookie::class)->constructor([
'secure' => true,
'path' => getenv('URL_BASE') ?: '/',
'httponly' => true,
'samesite'=> "Lax",
], getenv("LEAN_RANDOM")),
Session::class => create(Session::class)->constructor(get(Cookie::class), [ 'path' => getenv('URL_BASE') ?: '/', ]),
SessionMiddleware::class => create(SessionMiddleware::class)->constructor(get(Cookie::class), [
'name' => "lean_sess_" . substr(md5(getenv("LEAN_RANDOM")), 0, 12),
'path' => getenv('URL_BASE') ?: '/',
'samesite' => getenv("LEAN_COOKIE_SAMESITE") ?? "Lax",
'secure' => (bool) getenv('LEAN_COOKIE_SECURE') ?? false
]),
'error.401' => function(ContainerInterface $c, Picea $picea) { 'error.401' => function(ContainerInterface $c, Picea $picea) {
return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/401", []), 401); return $c->get(HttpFactoryInterface::class)::createHtmlResponse($picea->renderHtml("lean/error/401", []), 401);
}, },
+1
View File
@@ -71,6 +71,7 @@ return [
$router->addPatternMatcher('email', '[^@ \t\r\n/]+@[^@ \t\r\n/]+\.[^@ \t\r\n/]+'); $router->addPatternMatcher('email', '[^@ \t\r\n/]+@[^@ \t\r\n/]+\.[^@ \t\r\n/]+');
$router->addPatternMatcher('ids', '\b\d[\d,]*\b'); $router->addPatternMatcher('ids', '\b\d[\d,]*\b');
$routing = $container->get(Lean\Routing::class); $routing = $container->get(Lean\Routing::class);
$routing->registerRoute($container, getenv('URL_BASE')); $routing->registerRoute($container, getenv('URL_BASE'));
-9
View File
@@ -6,9 +6,6 @@ use TheBugs\JavascriptMiddleware;
use Lean\Lean; use Lean\Lean;
use Storage\Cookie,
Storage\Session,
Storage\SessionMiddleware;
use function DI\autowire, DI\create, DI\get, DI\add; use function DI\autowire, DI\create, DI\get, DI\add;
@@ -78,12 +75,6 @@ return [
JavascriptMiddleware::class => create(JavascriptMiddleware::class), JavascriptMiddleware::class => create(JavascriptMiddleware::class),
Cookie::class => create(Cookie::class)->constructor([ 'secure' => true, 'path' => getenv('URL_BASE') ?: '/', ], getenv("LEAN_RANDOM")),
Session::class => create(Session::class)->constructor(get(Cookie::class), [ 'path' => getenv('URL_BASE') ?: '/', ]),
SessionMiddleware::class => create(SessionMiddleware::class)->constructor(get(Cookie::class), [ 'name' => "lean_sess_" . substr(md5(getenv("LEAN_RANDOM")), 0, 12), 'path' => getenv('URL_BASE') ?: '/' ]),
'git.commit' => function($c) { 'git.commit' => function($c) {
if ( getenv("DEBUG") ) { if ( getenv("DEBUG") ) {
return uniqid("debug_"); return uniqid("debug_");
+31
View File
@@ -37,5 +37,36 @@ class ApplicationStrategy extends Strategy\ApplicationStrategy {
public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception): MiddlewareInterface public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception): MiddlewareInterface
{ {
return $this->getContainer()->has(MethodNotAllowedInterface::class) ? $this->getContainer()->get(MethodNotAllowedInterface::class) : parent::getMethodNotAllowedDecorator($exception); return $this->getContainer()->has(MethodNotAllowedInterface::class) ? $this->getContainer()->get(MethodNotAllowedInterface::class) : parent::getMethodNotAllowedDecorator($exception);
} }
/*=======
public function getMethodNotAllowedDecorator(MethodNotAllowedException $exception): MiddlewareInterface
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
if (php_sapi_name() !== 'cli' and ! defined('STDIN')) {
return $this->throw404($request);
}
return $handler->handle($request);;
}
public function throw404(ServerRequestInterface $request) : ResponseInterface
{
if ( getenv('DEBUG') && $this->di->has(\Picea\Asset\Asset::class) ) {
$params = $request->getServerParams();
$scpName = basename(explode('?', $params['REQUEST_URI'] ?? "", 2)[0]);
list(, $ext) = array_pad(explode('.', $scpName), 2, null);
if ($ext && in_array($ext, ApplicationStrategy::ASSET_TRIGGER_UPDATE)) {
$this->di->get(\Picea\Asset\Asset::class)->launchInstall();
}
}
return $this->di->get('error.404');
}
};
}
>>>>>>> af8b686 (- WIP on ulmus-user mechanics updates)*/
} }
+11
View File
@@ -9,6 +9,7 @@ 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 Picea\Ui\Method\FormContextInterface;
use Picea\Ui\Method\FormInterface;
use TheBugs\Email\MailerInterface; use TheBugs\Email\MailerInterface;
use Storage\{ Cookie, Session }; use Storage\{ Cookie, Session };
use League\CommonMark\CommonMarkConverter; use League\CommonMark\CommonMarkConverter;
@@ -210,6 +211,16 @@ trait ControllerTrait {
return $this->picea->compiler->getExtensionFromToken('route')->buildRouteUrl($name, $parameters); return $this->picea->compiler->getExtensionFromToken('route')->buildRouteUrl($name, $parameters);
} }
#[Ignore]
public function form(FormInterface $form, ? FormContextInterface $formContext = null) : Picea\Ui\Method\FormHandler
{
if (! $this->picea ) {
throw new \Exception("A picea object must be provided on class initialization to use this method.");
}
return $this->picea->compiler->getExtensionInstanceOf(Picea\Ui\Method\Form::class)->formClass($form, $formContext);
}
#[Ignore] #[Ignore]
public function json($data, int $flags = 0) : string public function json($data, int $flags = 0) : string
{ {
+8 -4
View File
@@ -24,7 +24,7 @@ class Kernel
public array $paths = []; public array $paths = [];
public int $errorReportingDev = -1; public int $errorReportingDev = -1 & ~E_USER_DEPRECATED & ~E_DEPRECATED ;
public int $errorReportingProd = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED /*& ~E_NOTICE*/; public int $errorReportingProd = E_ALL & ~E_USER_DEPRECATED & ~E_DEPRECATED /*& ~E_NOTICE*/;
@@ -34,10 +34,12 @@ class Kernel
public function __construct( public function __construct(
public string $projectPath public string $projectPath
) ) {
{
# Still not sure about adding a folder check each call just to add a basic project setup error ... # Still not sure about adding a folder check each call just to add a basic project setup error ...
# File::assertFolderExists($this->projectPath); # File::assertFolderExists($this->projectPath);
define('IS_CLI', php_sapi_name() === 'cli' OR defined('STDIN'));
$this->setEnvironment(); $this->setEnvironment();
$this->initializeEngine(); $this->initializeEngine();
$this->setupContainer(); $this->setupContainer();
@@ -78,10 +80,12 @@ class Kernel
$path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey); $path = getenv("PROJECT_PATH") . DIRECTORY_SEPARATOR . getenv($envkey);
if (getenv('DEBUG') && ! file_exists($path)) { if (getenv('DEBUG') && ! file_exists($path)) {
if (false === mkdir($path, 0755, true)) { if (false === @mkdir($path, 0755, true)) {
if (! IS_CLI) {
throw new \Exception(sprintf("Folder '%s' could not be created", $path)); throw new \Exception(sprintf("Folder '%s' could not be created", $path));
} }
} }
}
static::putenv($name, realpath($path)); static::putenv($name, realpath($path));
} }
+5
View File
@@ -44,6 +44,11 @@ class Routing {
$container->set(ServerRequestInterface::class, $request); $container->set(ServerRequestInterface::class, $request);
# Decoding arguments received from the router
foreach($arguments as &$arg) {
$arg = urldecode($arg);
}
return $this->response ?? $object->$method($request, $arguments); return $this->response ?? $object->$method($request, $arguments);
}); });
} }