mirror of
https://github.com/flarum/framework.git
synced 2024-11-28 11:34:36 +08:00
Switch admin app to new PSR-7 driven architecture
This commit is contained in:
parent
95677e05e3
commit
7ab3437136
|
@ -1,18 +1,17 @@
|
||||||
<?php namespace Flarum\Admin\Actions;
|
<?php namespace Flarum\Admin\Actions;
|
||||||
|
|
||||||
use Flarum\Support\Action;
|
use Flarum\Support\HtmlAction;
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Session;
|
use Session;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Cookie;
|
use Cookie;
|
||||||
use Config;
|
use Config;
|
||||||
use View;
|
|
||||||
use DB;
|
use DB;
|
||||||
use Flarum\Api\Request as ApiRequest;
|
use Flarum\Api\Request as ApiRequest;
|
||||||
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
||||||
|
|
||||||
class IndexAction extends Action
|
class IndexAction extends HtmlAction
|
||||||
{
|
{
|
||||||
public function handle(Request $request, $params = [])
|
protected function render(Request $request, $routeParams = [])
|
||||||
{
|
{
|
||||||
$config = DB::table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
|
$config = DB::table('config')->whereIn('key', ['base_url', 'api_url', 'forum_title', 'welcome_title', 'welcome_message'])->lists('value', 'key');
|
||||||
$data = [];
|
$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('title', 'Administration - '.Config::get('flarum::forum_title', 'Flarum Demo Forum'))
|
||||||
->with('config', $config)
|
->with('config', $config)
|
||||||
->with('layout', 'flarum.admin::admin')
|
->with('layout', 'flarum.admin::admin')
|
||||||
|
|
|
@ -2,10 +2,15 @@
|
||||||
|
|
||||||
use Flarum\Support\Actor;
|
use Flarum\Support\Actor;
|
||||||
use Flarum\Core\Models\AccessToken;
|
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;
|
protected $actor;
|
||||||
|
|
||||||
public function __construct(Actor $actor)
|
public function __construct(Actor $actor)
|
||||||
|
@ -13,16 +18,22 @@ class LoginWithCookieAndCheckAdmin
|
||||||
$this->actor = $actor;
|
$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 = AccessToken::where('id', $token)->first()) &&
|
||||||
$accessToken->user->isAdmin()) {
|
$accessToken->user->isAdmin()
|
||||||
|
) {
|
||||||
$this->actor->setUser($accessToken->user);
|
$this->actor->setUser($accessToken->user);
|
||||||
} else {
|
} else {
|
||||||
die('ur not an admin');
|
die('ur not an admin');
|
||||||
}
|
}
|
||||||
|
|
||||||
return $next($request);
|
return $out ? $out($request, $response) : $response;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,19 +1,16 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
use Psr\Http\Message\ServerRequestInterface;
|
||||||
|
|
||||||
$action = function ($class) {
|
$action = function ($class) {
|
||||||
return function () use ($class) {
|
return function (ServerRequestInterface $httpRequest, $routeParams) use ($class) {
|
||||||
$action = $this->app->make($class);
|
$action = $this->app->make($class);
|
||||||
$request = $this->app['request']->instance();
|
|
||||||
$parameters = $this->app['router']->current()->parameters();
|
return $action->handle($httpRequest, $routeParams);
|
||||||
return $action->handle($request, $parameters);
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
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('/', [
|
$router->get('/admin', 'flarum.admin.index', $action('Flarum\Admin\Actions\IndexAction'));
|
||||||
'as' => 'flarum.admin.index',
|
|
||||||
'uses' => $action('Flarum\Admin\Actions\IndexAction')
|
|
||||||
]);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user