ServerManager project files

This commit is contained in:
2026-06-06 17:58:34 -04:00
parent ce1863d955
commit 9c0bc7f189
502 changed files with 87837 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
<?php
declare(strict_types=1);
namespace ServerManager\Middleware;
use ServerManager\Core\Session;
class AuthMiddleware
{
public function handle(): mixed
{
if (!Session::has('user_id')) {
Session::setFlash('error', 'You must be logged in to access this page.');
$this->redirect('/login');
}
if (Session::get('session_expiry') && time() > Session::get('session_expiry')) {
Session::destroy();
Session::setFlash('error', 'Your session has expired. Please log in again.');
$this->redirect('/login');
}
return null;
}
private function redirect(string $url): never
{
if (!headers_sent()) {
header("Location: {$url}");
} else {
echo '<script>window.location.href="' . $url . '";</script>';
}
exit;
}
}