From bbd2625752b6f2f28f70a4401be472639523c419 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Wed, 27 May 2015 03:02:10 +0200 Subject: [PATCH] Switch admin app to new PSR-7 driven architecture --- .../core/src/Admin/Actions/IndexAction.php | 11 ++++----- .../LoginWithCookieAndCheckAdmin.php | 23 ++++++++++++++----- framework/core/src/Admin/routes.php | 19 +++++++-------- 3 files changed, 30 insertions(+), 23 deletions(-) diff --git a/framework/core/src/Admin/Actions/IndexAction.php b/framework/core/src/Admin/Actions/IndexAction.php index e26e5de25..1398482d9 100644 --- a/framework/core/src/Admin/Actions/IndexAction.php +++ b/framework/core/src/Admin/Actions/IndexAction.php @@ -1,18 +1,17 @@ whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key'); $data = []; @@ -35,7 +34,7 @@ class IndexAction extends Action } } - $view = View::make('flarum.admin::index') + $view = view('flarum.admin::index') ->with('title', 'Administration - '.Config::get('flarum::forum_title', 'Flarum Demo Forum')) ->with('config', $config) ->with('layout', 'flarum.admin::admin') diff --git a/framework/core/src/Admin/Middleware/LoginWithCookieAndCheckAdmin.php b/framework/core/src/Admin/Middleware/LoginWithCookieAndCheckAdmin.php index b332a8cd2..2cf71d4b8 100644 --- a/framework/core/src/Admin/Middleware/LoginWithCookieAndCheckAdmin.php +++ b/framework/core/src/Admin/Middleware/LoginWithCookieAndCheckAdmin.php @@ -2,10 +2,15 @@ use Flarum\Support\Actor; use Flarum\Core\Models\AccessToken; -use Closure; +use Psr\Http\Message\ResponseInterface as Response; +use Psr\Http\Message\ServerRequestInterface as Request; +use Zend\Stratigility\MiddlewareInterface; -class LoginWithCookieAndCheckAdmin +class LoginWithCookieAndCheckAdmin implements MiddlewareInterface { + /** + * @var Actor + */ protected $actor; public function __construct(Actor $actor) @@ -13,16 +18,22 @@ class LoginWithCookieAndCheckAdmin $this->actor = $actor; } - public function handle($request, Closure $next) + /** + * {@inheritdoc} + */ + public function __invoke(Request $request, Response $response, callable $out = null) { - if (($token = $request->cookie('flarum_remember')) && + $cookies = $request->getCookieParams(); + + if (($token = $cookies['flarum_remember']) && ($accessToken = AccessToken::where('id', $token)->first()) && - $accessToken->user->isAdmin()) { + $accessToken->user->isAdmin() + ) { $this->actor->setUser($accessToken->user); } else { die('ur not an admin'); } - return $next($request); + return $out ? $out($request, $response) : $response; } } diff --git a/framework/core/src/Admin/routes.php b/framework/core/src/Admin/routes.php index 44127ab83..75f32da8c 100755 --- a/framework/core/src/Admin/routes.php +++ b/framework/core/src/Admin/routes.php @@ -1,19 +1,16 @@ app->make($class); - $request = $this->app['request']->instance(); - $parameters = $this->app['router']->current()->parameters(); - return $action->handle($request, $parameters); + + return $action->handle($httpRequest, $routeParams); }; }; -Route::group(['prefix' => 'admin', 'middleware' => 'Flarum\Admin\Middleware\LoginWithCookieAndCheckAdmin'], function () use ($action) { +/** @var Flarum\Http\Router $router */ +$router = $this->app->make('Flarum\Http\Router'); - Route::get('/', [ - 'as' => 'flarum.admin.index', - 'uses' => $action('Flarum\Admin\Actions\IndexAction') - ]); - -}); +$router->get('/admin', 'flarum.admin.index', $action('Flarum\Admin\Actions\IndexAction'));