diff --git a/src/Admin/Actions/IndexAction.php b/src/Admin/Actions/IndexAction.php index e26e5de25..1398482d9 100644 --- a/src/Admin/Actions/IndexAction.php +++ b/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/src/Admin/Middleware/LoginWithCookieAndCheckAdmin.php b/src/Admin/Middleware/LoginWithCookieAndCheckAdmin.php index b332a8cd2..2cf71d4b8 100644 --- a/src/Admin/Middleware/LoginWithCookieAndCheckAdmin.php +++ b/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/src/Admin/routes.php b/src/Admin/routes.php index 44127ab83..75f32da8c 100755 --- a/src/Admin/routes.php +++ b/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'));