isLoggedIn()) { header('Location: index.php'); exit; } } catch (Exception $e) { die('Fehler beim Initialisieren: ' . $e->getMessage()); } $error = ''; $success = ''; // Login-Verarbeitung if ($_SERVER['REQUEST_METHOD'] === 'POST') { try { $email = trim($_POST['email'] ?? ''); $password = $_POST['password'] ?? ''; if (empty($email) || empty($password)) { $error = 'Bitte E-Mail und Passwort eingeben'; } else { $result = $auth->login($email, $password); if ($result === true) { header('Location: index.php'); exit; } elseif ($result === 'rate_limited') { $error = 'Zu viele Fehlversuche. Bitte warten Sie 10 Minuten.'; } 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', ''); // M365 aktiviert prüfen - ALLE drei Felder müssen ausgefüllt sein $m365ClientId = $db->getSetting('m365_client_id', ''); $m365ClientSecret = $db->getSetting('m365_client_secret', ''); $m365TenantId = $db->getSetting('m365_tenant_id', ''); $m365Enabled = !empty($m365ClientId) && !empty($m365ClientSecret) && !empty($m365TenantId); $publicAccess = $db->getSetting('public_access', 0); // M365 OAuth URL generieren falls aktiviert $m365LoginUrl = ''; if ($m365Enabled) { // 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' => $m365ClientId, '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/$m365TenantId/oauth2/v2.0/authorize?" . http_build_query($params); } // Prüfen ob alternative Login-Form (Benutzername/Passwort) angezeigt werden soll $showLocalLogin = isset($_GET['local']) && $_GET['local'] === '1'; } catch (Exception $e) { die('Datenbankfehler: ' . $e->getMessage()); } ?> Login - <?= htmlspecialchars($appTitle) ?>

Melden Sie sich an, um fortzufahren

Mit Microsoft anmelden Mit Benutzername und Passwort anmelden
oder
Mit Microsoft anmelden ← Zurück zur Code-Erstellung