first commit
This commit is contained in:
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Core\Auth;
|
||||
use App\Core\View;
|
||||
|
||||
class AdminController
|
||||
{
|
||||
protected function requireAdmin(): void
|
||||
{
|
||||
if (!Auth::check()) {
|
||||
header('Location: /login');
|
||||
exit;
|
||||
}
|
||||
|
||||
$user = Auth::user();
|
||||
|
||||
if ((int)($user['is_admin'] ?? 0) !== 1) {
|
||||
http_response_code(403);
|
||||
echo 'Доступ запрещен';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
public function index(): void
|
||||
{
|
||||
$this->requireAdmin();
|
||||
|
||||
View::render('admin/index', [
|
||||
'user' => Auth::user(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user