37 lines
643 B
PHP
37 lines
643 B
PHP
<?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(),
|
|
]);
|
|
}
|
|
} |