getMessage(); } try { if (!file_exists(__DIR__ . '/includes/Database.php')) { throw new Exception('includes/Database.php nicht gefunden'); } require_once __DIR__ . '/includes/Database.php'; } catch (Exception $e) { $loadErrors[] = "Database: " . $e->getMessage(); } try { if (!file_exists(__DIR__ . '/includes/Auth.php')) { throw new Exception('includes/Auth.php nicht gefunden'); } require_once __DIR__ . '/includes/Auth.php'; } catch (Exception $e) { $loadErrors[] = "Auth: " . $e->getMessage(); } // Wenn Ladefehler aufgetreten sind, zeige sie an if (!empty($loadErrors)) { die('

Fehler beim Laden der Dateien

'); } // Ab hier normal weiter try { $auth = new Auth(); } catch (Exception $e) { die('

Fehler bei Auth-Initialisierung

' . $e->getMessage() . '

'); } // Wenn bereits eingeloggt, weiterleiten if ($auth->isLoggedIn()) { header('Location: index.php'); exit; } $error = ''; $success = ''; // Login-Verarbeitung if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { $email = $_POST['email'] ?? ''; $password = $_POST['password'] ?? ''; if (empty($email) || empty($password)) { $error = 'Bitte E-Mail und Passwort eingeben'; } elseif ($auth->login($email, $password)) { header('Location: index.php'); exit; } else { $error = 'Ungültige E-Mail oder Passwort'; } } catch (Exception $e) { $error = 'Login-Fehler: ' . $e->getMessage(); } } try { $db = Database::getInstance(); $appTitle = $db->getSetting('app_title', 'UniFi Voucher System'); $logoUrl = $db->getSetting('logo_url', ''); $m365Enabled = !empty($db->getSetting('m365_client_id')) && !empty($db->getSetting('m365_client_secret')) && !empty($db->getSetting('m365_tenant_id')); $publicAccess = $db->getSetting('public_access', 0); // M365 OAuth URL generieren falls aktiviert $m365LoginUrl = ''; if ($m365Enabled) { $clientId = $db->getSetting('m365_client_id'); $tenantId = $db->getSetting('m365_tenant_id'); // Dynamische Redirect URI basierend auf aktuellem Pfad $protocol = isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] === 'on' ? 'https' : 'http'; $host = $_SERVER['HTTP_HOST']; $scriptPath = dirname($_SERVER['SCRIPT_NAME']); $scriptPath = $scriptPath === '/' ? '' : $scriptPath; $redirectUri = $protocol . '://' . $host . $scriptPath . '/m365_callback.php'; $params = [ 'client_id' => $clientId, 'response_type' => 'code', 'redirect_uri' => $redirectUri, 'response_mode' => 'query', 'scope' => 'openid profile email User.Read', 'state' => bin2hex(random_bytes(16)) ]; $_SESSION['m365_state'] = $params['state']; $m365LoginUrl = "https://login.microsoftonline.com/$tenantId/oauth2/v2.0/authorize?" . http_build_query($params); } } catch (Exception $e) { die('

Datenbankfehler

' . $e->getMessage() . '

'); } ?> Login - <?= htmlspecialchars($appTitle) ?>

Melden Sie sich an, um fortzufahren

oder
Mit Microsoft 365 anmelden
System-Status:
PHP Version:
Session Status:
Eingeloggt: isLoggedIn() ? 'Ja' : 'Nein' ?>