prepare("SELECT * FROM admin WHERE username = ?"); $stmt->bind_param("s", $username); $stmt->execute(); $res = $stmt->get_result(); if ($row = $res->fetch_assoc()) { if (password_verify($password, $row['password'])) { $_SESSION['admin'] = $row['username']; $_SESSION['auth_type'] = 'local'; header("Location: index.php"); exit; } } $error = "Credenziali non valide"; } catch (Exception $e) { $error = "Errore durante l'autenticazione. Potrebbe essere un problema con PHP oppure col database. Ulteriori dettagli: " . $e; } } if (AUTH_TYPE == 'local') { echo <<
Copyright (C) 2025 EmmeV. - Released under GNU AGPL 3.0 License.
HTML; } else if (AUTH_TYPE === 'keycloak') { try { // Configura il client Keycloak $oidc = new OpenIDConnectClient( 'https://' . KEYCLOAK_DOMAIN . '/realms/' . KEYCLOAK_REALM . '/', KEYCLOAK_CLIENT_ID, KEYCLOAK_CLIENT_SECRET ); // Redirect post-login $oidc->setRedirectURL('https://' . APP_DOMAIN . '/admin/login.php'); $oidc->authenticate(); $userinfo = $oidc->getVerifiedClaims(); if (in_array($userinfo->preferred_username, KEYCLOAK_ALLOWED_USERS, true) || empty(KEYCLOAK_ALLOWED_USERS)) { $_SESSION['admin'] = $userinfo->preferred_username; $_SESSION['auth_type'] = 'keycloak'; header("Location: index.php"); exit; } else { http_response_code(403); echo <<Copyright (C) 2025 EmmeV. - Released under GNU AGPL 3.0 License.
HTML; exit; } } catch (Exception $e) { http_response_code(500); echo <<Copyright (C) 2025 EmmeV. - Released under GNU AGPL 3.0 License.
HTML; exit; } } ?>