Initial Commit

This commit is contained in:
Hosteroid
2025-10-08 14:23:07 +03:00
commit b3b3ac66ff
78 changed files with 14248 additions and 0 deletions

59
core/Auth.php Normal file
View File

@@ -0,0 +1,59 @@
<?php
namespace Core;
class Auth
{
/**
* Check if user is authenticated
*/
public static function check(): bool
{
return isset($_SESSION['user_id']);
}
/**
* Get current user ID
*/
public static function id(): ?int
{
return $_SESSION['user_id'] ?? null;
}
/**
* Get current username
*/
public static function username(): ?string
{
return $_SESSION['username'] ?? null;
}
/**
* Get current user's full name
*/
public static function fullName(): ?string
{
return $_SESSION['full_name'] ?? null;
}
/**
* Require authentication (redirect to login if not authenticated)
*/
public static function require(): void
{
// Get current path
$currentPath = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
// Don't redirect if already on login page or logout
if ($currentPath === '/login' || $currentPath === '/logout') {
return;
}
if (!self::check()) {
$_SESSION['error'] = 'Please login to continue';
header('Location: /login');
exit;
}
}
}