- Removed authentication from controller, now handled by middleware
This commit is contained in:
parent
2cb911ea6f
commit
2378245dbf
|
@ -15,7 +15,7 @@ use Storage\{ Cookie, Session };
|
||||||
use function DI\{get, autowire, create};
|
use function DI\{get, autowire, create};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Authenticate::class => create(Authenticate::class)->constructor(get(Session::class), get(Cookie::class), get('authentication.method')),
|
Authenticate::class => create(Authenticate::class)->constructor(get(Entity\UserInterface::class), get(Session::class), get(Cookie::class), get('authentication.method')),
|
||||||
|
|
||||||
HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authorize.error')),
|
HeaderAuthenticationMiddleware::class => create(HeaderAuthenticationMiddleware::class)->constructor(get(Entity\UserInterface::class), get('authorize.error')),
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,11 @@ use Notes\Breadcrumb\Breadcrumb;
|
||||||
|
|
||||||
use Storage\SessionMiddleware;
|
use Storage\SessionMiddleware;
|
||||||
|
|
||||||
|
use Ulmus\User\Middleware\{
|
||||||
|
HeaderAuthenticationMiddleware,
|
||||||
|
PostRequestAuthenticationMiddleware
|
||||||
|
};
|
||||||
|
|
||||||
return [
|
return [
|
||||||
Lean\Routing::class => autowire(Lean\Routing::class),
|
Lean\Routing::class => autowire(Lean\Routing::class),
|
||||||
|
|
||||||
|
@ -44,14 +49,17 @@ return [
|
||||||
"dump", "errorHandler", SessionMiddleware::class, CronardMiddleware::class, Mcnd\Event\EventMiddleware::class, Mcnd\CLI\CliMiddleware::class,
|
"dump", "errorHandler", SessionMiddleware::class, CronardMiddleware::class, Mcnd\Event\EventMiddleware::class, Mcnd\CLI\CliMiddleware::class,
|
||||||
],
|
],
|
||||||
|
|
||||||
'app.middlewares' => [],
|
'app.middlewares' => [
|
||||||
|
HeaderAuthenticationMiddleware::class,
|
||||||
|
PostRequestAuthenticationMiddleware::class,
|
||||||
|
],
|
||||||
|
|
||||||
'routes.list' => function($c) {
|
'routes.list' => function($c) {
|
||||||
return function (ContainerInterface $container) {
|
return function (ContainerInterface $container) {
|
||||||
$router = $container->get(Router::class);
|
$router = $container->get(Router::class);
|
||||||
|
|
||||||
foreach([ 'routes.middlewares', 'app.middlewares' ] as $key) {
|
foreach([ 'routes.middlewares', 'app.middlewares' ] as $key) {
|
||||||
if ($container->has('app.middlewares')) {
|
if ( $container->has($key) ) {
|
||||||
foreach ($container->get($key) as $i => $middleware) {
|
foreach ($container->get($key) as $i => $middleware) {
|
||||||
if ($container->has($middleware)) {
|
if ($container->has($middleware)) {
|
||||||
$router->middleware($container->get($middleware));
|
$router->middleware($container->get($middleware));
|
||||||
|
|
|
@ -47,9 +47,11 @@ return array_merge(
|
||||||
require("$dir/security.php"),
|
require("$dir/security.php"),
|
||||||
require("$dir/env/" . getenv('APP_ENV') . ".php"),
|
require("$dir/env/" . getenv('APP_ENV') . ".php"),
|
||||||
[
|
[
|
||||||
'config' => function () { return array_replace(
|
'config' => function () {
|
||||||
require(getenv("META_PATH")."/config.php"),
|
return array_merge_recursive(
|
||||||
Lean\Lean::autoloadConfigFromComposerExtra(),
|
Lean\Lean::autoloadConfigFromComposerExtra(),
|
||||||
); }
|
require(getenv("META_PATH")."/config.php")
|
||||||
|
);
|
||||||
|
}
|
||||||
]
|
]
|
||||||
);
|
);
|
||||||
|
|
|
@ -5,36 +5,33 @@ namespace %NAMESPACE%\Lib;
|
||||||
use Picea\Picea;
|
use Picea\Picea;
|
||||||
use Storage\Session;
|
use Storage\Session;
|
||||||
use Ulmus\User\Entity\User;
|
use Ulmus\User\Entity\User;
|
||||||
use Ulmus\User\Lib\Authenticate;
|
|
||||||
use Notes\Route\Attribute\Object\Route;
|
use Notes\Route\Attribute\Object\Route;
|
||||||
use Notes\Security\Attribute\Security;
|
use Notes\Security\Attribute\Security;
|
||||||
|
|
||||||
use %NAMESPACE%\{ Entity, Lib, Form };
|
use %NAMESPACE%\{ Entity, Lib, Form };
|
||||||
|
|
||||||
use Mcnd\Event\EventManager;
|
use Mcnd\Event\EventManager;
|
||||||
|
use Ulmus\User\Entity\UserInterface;
|
||||||
|
|
||||||
#[Security(locked: false)]
|
#[Security(locked: false)]
|
||||||
#[Route(method: ['GET', 'POST', ])]
|
#[Route(method: ['GET', 'POST', ])]
|
||||||
trait ControllerTrait {
|
trait ControllerTrait {
|
||||||
use \Lean\ControllerTrait;
|
use \Lean\ControllerTrait;
|
||||||
|
|
||||||
public ? \Ulmus\User\Entity\User $user;
|
public ? UserInterface $user;
|
||||||
|
|
||||||
protected Authenticate $authenticate;
|
|
||||||
|
|
||||||
protected EventManager $eventManager;
|
protected EventManager $eventManager;
|
||||||
|
|
||||||
public function __construct(Picea $picea, Session $session, Authenticate $authenticate, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
public function __construct(Picea $picea, Session $session, UserInterface $user, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
||||||
$this->initializeController($picea, $session, $authenticate, $breadcrumb, $eventManager);
|
$this->initializeController($picea, $session, $user, $breadcrumb, $eventManager);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function initializeController(Picea $picea, Session $session, Authenticate $authenticate, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
public function initializeController(Picea $picea, Session $session, UserInterface $user, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
||||||
$this->picea = $picea;
|
$this->picea = $picea;
|
||||||
$this->authenticate = $authenticate;
|
|
||||||
$this->session = $session;
|
$this->session = $session;
|
||||||
$this->eventManager = $eventManager;
|
$this->eventManager = $eventManager;
|
||||||
$this->breadcrumb = $breadcrumb;
|
$this->breadcrumb = $breadcrumb;
|
||||||
$this->user = $authenticate->rememberMe( Entity\User::repository() ) ?: new Entity\User();
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
|
||||||
namespace Lean;
|
namespace Lean;
|
||||||
|
|
||||||
|
|
||||||
class Application
|
class Application
|
||||||
{
|
{
|
||||||
public string $name;
|
public string $name;
|
||||||
|
|
Loading…
Reference in New Issue