Files
MoneyFlix/crm/Core/AuthMiddleware.php
T
1sonhador 9d43854277 feat: Initial MoneyFlix project setup
- Created separate MoneyFlix project directory
- Copied Node.js redirector from production server
- Added CRM PHP code (Redirects module, Core classes, Config, Routes, Views)
- Created comprehensive documentation (README_MONEYFLIX.md)
- Added sync script to keep CRM code updated (sync-from-crm.sh)
- Configured .gitignore for Node.js and PHP
- Set up proper project structure for multi-client isolation

This separates MoneyFlix from the main CRM to avoid confusion
between different client systems and provides a dedicated
environment for MoneyFlix-specific development and maintenance.
2025-10-03 12:09:41 +01:00

61 lines
1.3 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Core;
class AuthMiddleware
{
/**
* Check if user is authenticated. If not, redirect to login page.
*/
public static function requireAuth(): void
{
if (!Auth::check()) {
header('Location: /login');
exit();
}
}
/**
* Check if user has a specific role.
*/
public static function requireRole(string $role): void
{
self::requireAuth();
$user = Auth::user();
if (!$user || $user['role'] !== $role) {
// Or redirect to a "403 Forbidden" page
header('Location: /');
exit;
}
}
/**
* Check if user has admin role.
*/
public static function requireAdmin(): void
{
self::requireRole('admin');
}
/**
* If user is already logged in, redirect them from login/register pages.
*/
public static function redirectIfAuthenticated(): void
{
if (Auth::check()) {
header('Location: /apps/users/profile'); // Redirect to profile or dashboard
exit();
}
}
public function requireGuest(): void
{
if (Auth::check()) {
header('Location: /apps/users/profile'); // Redirect to profile or dashboard
exit();
}
}
}