| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748 |
- <?php
- /**
- * lib/auth.php
- *
- * Authentication and authorization functions.
- */
- /**
- * Check if user is logged in
- */
- function isLoggedIn(): bool
- {
- return isset($_SESSION['user_id']) && !empty($_SESSION['user_id']);
- }
- /**
- * Get current user ID
- */
- function getCurrentUserId(): ?int
- {
- return $_SESSION['user_id'] ?? null;
- }
- /**
- * Require user to be logged in, redirect if not
- */
- function requireLogin(): void
- {
- if (!isLoggedIn()) {
- header('Location: /login/login.php');
- exit;
- }
- }
- /**
- * Check if user has specific role/permission
- */
- function hasPermission(string $permission): bool
- {
- if (!isLoggedIn()) {
- return false;
- }
- // TODO: Implement proper role-based permissions
- // For now, just check if user is logged in
- return true;
- }
- ?>
|