初始提交:卡密授权管理系统
This commit is contained in:
commit
59586775c4
202 files changed
+25427
No files matched your search
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
namespace App\Middleware;
|
||||
|
||||
use App\Core\Middleware;
|
||||
use App\Core\Application;
|
||||
|
||||
/**
|
||||
* 角色权限中间件
|
||||
* 验证用户角色是否在允许列表中
|
||||
*/
|
||||
class RoleMiddleware
|
||||
{
|
||||
private string $role;
|
||||
|
||||
public function __construct(string $role)
|
||||
{
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
public function handle(array $request, callable $next): mixed
|
||||
{
|
||||
$userRole = $_SERVER['HTTP_X_USER_ROLE'] ?? '';
|
||||
|
||||
if ($this->role === 'admin') {
|
||||
if ($userRole !== 'admin') {
|
||||
Application::jsonResponse(403, '仅超级管理员可操作', null, 403);
|
||||
}
|
||||
} elseif ($this->role === 'admin_or_project_admin') {
|
||||
if (!in_array($userRole, ['admin', 'project_admin'])) {
|
||||
Application::jsonResponse(403, '无权限操作', null, 403);
|
||||
}
|
||||
} elseif ($this->role === 'agent') {
|
||||
if ($userRole !== 'agent') {
|
||||
Application::jsonResponse(403, '仅代理可操作', null, 403);
|
||||
}
|
||||
}
|
||||
|
||||
return $next($request);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user