You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.3 KiB
PHP
43 lines
1.3 KiB
PHP
<?php
|
|
|
|
namespace App\Middleware;
|
|
|
|
use App\Services\AdminPermission;
|
|
use App\Services\AdminCsrf;
|
|
use Psr\Http\Message\ResponseInterface;
|
|
use Psr\Http\Message\ServerRequestInterface;
|
|
|
|
class SuperAdmin
|
|
{
|
|
public function __invoke(ServerRequestInterface $request, ResponseInterface $response, $next)
|
|
{
|
|
if (!AdminPermission::isSuperAdmin()) {
|
|
$payload = json_encode([
|
|
'ret' => 0,
|
|
'msg' => '只有超级管理员可以执行此操作',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
|
|
$response->getBody()->write($payload);
|
|
|
|
return $response
|
|
->withStatus(403)
|
|
->withHeader('Content-Type', 'application/json; charset=utf-8');
|
|
}
|
|
|
|
if (AdminCsrf::requiresProtection($request->getMethod()) && !AdminCsrf::verify($request)) {
|
|
$payload = json_encode([
|
|
'ret' => 0,
|
|
'msg' => '页面安全令牌已失效,请刷新页面后重试',
|
|
], JSON_UNESCAPED_UNICODE);
|
|
|
|
$response->getBody()->write($payload);
|
|
|
|
return $response
|
|
->withStatus(419, 'Authentication Timeout')
|
|
->withHeader('Content-Type', 'application/json; charset=utf-8');
|
|
}
|
|
|
|
return $next($request, $response);
|
|
}
|
|
}
|