- 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};
|
||||
|
||||
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')),
|
||||
|
||||
|
|
|
@ -15,6 +15,11 @@ use Notes\Breadcrumb\Breadcrumb;
|
|||
|
||||
use Storage\SessionMiddleware;
|
||||
|
||||
use Ulmus\User\Middleware\{
|
||||
HeaderAuthenticationMiddleware,
|
||||
PostRequestAuthenticationMiddleware
|
||||
};
|
||||
|
||||
return [
|
||||
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,
|
||||
],
|
||||
|
||||
'app.middlewares' => [],
|
||||
'app.middlewares' => [
|
||||
HeaderAuthenticationMiddleware::class,
|
||||
PostRequestAuthenticationMiddleware::class,
|
||||
],
|
||||
|
||||
'routes.list' => function($c) {
|
||||
return function (ContainerInterface $container) {
|
||||
$router = $container->get(Router::class);
|
||||
|
||||
foreach([ 'routes.middlewares', 'app.middlewares' ] as $key) {
|
||||
if ($container->has('app.middlewares')) {
|
||||
if ( $container->has($key) ) {
|
||||
foreach ($container->get($key) as $i => $middleware) {
|
||||
if ($container->has($middleware)) {
|
||||
$router->middleware($container->get($middleware));
|
||||
|
|
|
@ -47,9 +47,11 @@ return array_merge(
|
|||
require("$dir/security.php"),
|
||||
require("$dir/env/" . getenv('APP_ENV') . ".php"),
|
||||
[
|
||||
'config' => function () { return array_replace(
|
||||
require(getenv("META_PATH")."/config.php"),
|
||||
'config' => function () {
|
||||
return array_merge_recursive(
|
||||
Lean\Lean::autoloadConfigFromComposerExtra(),
|
||||
); }
|
||||
require(getenv("META_PATH")."/config.php")
|
||||
);
|
||||
}
|
||||
]
|
||||
);
|
||||
|
|
|
@ -5,36 +5,33 @@ namespace %NAMESPACE%\Lib;
|
|||
use Picea\Picea;
|
||||
use Storage\Session;
|
||||
use Ulmus\User\Entity\User;
|
||||
use Ulmus\User\Lib\Authenticate;
|
||||
use Notes\Route\Attribute\Object\Route;
|
||||
use Notes\Security\Attribute\Security;
|
||||
|
||||
use %NAMESPACE%\{ Entity, Lib, Form };
|
||||
|
||||
use Mcnd\Event\EventManager;
|
||||
use Ulmus\User\Entity\UserInterface;
|
||||
|
||||
#[Security(locked: false)]
|
||||
#[Route(method: ['GET', 'POST', ])]
|
||||
trait ControllerTrait {
|
||||
use \Lean\ControllerTrait;
|
||||
|
||||
public ? \Ulmus\User\Entity\User $user;
|
||||
|
||||
protected Authenticate $authenticate;
|
||||
public ? UserInterface $user;
|
||||
|
||||
protected EventManager $eventManager;
|
||||
|
||||
public function __construct(Picea $picea, Session $session, Authenticate $authenticate, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $eventManager) {
|
||||
$this->initializeController($picea, $session, $authenticate, $breadcrumb, $eventManager);
|
||||
public function __construct(Picea $picea, Session $session, UserInterface $user, \Notes\Breadcrumb\Breadcrumb $breadcrumb, EventManager $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->authenticate = $authenticate;
|
||||
$this->session = $session;
|
||||
$this->eventManager = $eventManager;
|
||||
$this->breadcrumb = $breadcrumb;
|
||||
$this->user = $authenticate->rememberMe( Entity\User::repository() ) ?: new Entity\User();
|
||||
$this->user = $user;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,9 +1,7 @@
|
|||
<?php
|
||||
|
||||
|
||||
namespace Lean;
|
||||
|
||||
|
||||
class Application
|
||||
{
|
||||
public string $name;
|
||||
|
|
Loading…
Reference in New Issue