Files
desktop/public/api/module-auth/mining-checker/index.php
Lars Gebhardt-Kusche 033fdfd598
All checks were successful
Deploy / deploy-staging (push) Successful in 24s
Deploy / deploy-production (push) Has been skipped
dadasd
2026-06-15 22:15:01 +02:00

67 lines
2.2 KiB
PHP

<?php
declare(strict_types=1);
require_once dirname(__DIR__, 5) . '/src/App/bootstrap.php';
use App\ConfigLoader;
use App\AccountGate;
use App\KeycloakAuth;
use MiningChecker\LegacyModuleStore;
use MiningChecker\MiningCheckerUserScope;
session_start();
$projectRoot = dirname(__DIR__, 5);
$auth = new KeycloakAuth(ConfigLoader::load($projectRoot, 'keycloak'));
$accountGate = new AccountGate(ConfigLoader::load($projectRoot, 'registration'));
header('Content-Type: application/json; charset=utf-8');
if ($auth->isAuthenticated()) {
$currentUser = is_array($_SESSION['desktop_auth']['user'] ?? null) ? $_SESSION['desktop_auth']['user'] : [];
$accountCheck = $accountGate->checkUsername((string) ($currentUser['username'] ?? ''));
if (!($accountCheck['allowed'] ?? false)) {
$auth->logout();
http_response_code(403);
echo json_encode(['error' => (string) ($accountCheck['message'] ?? 'Dieses Konto ist noch nicht freigeschaltet.')], JSON_UNESCAPED_UNICODE);
exit;
}
}
if (!$auth->shouldShowDesktop()) {
http_response_code(401);
echo json_encode(['error' => 'Nicht autorisiert.'], JSON_UNESCAPED_UNICODE);
exit;
}
$store = new LegacyModuleStore($projectRoot, MiningCheckerUserScope::current());
$method = strtoupper((string) ($_SERVER['REQUEST_METHOD'] ?? 'GET'));
if ($method === 'GET') {
echo json_encode($store->loadAuth(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
if ($method === 'PUT') {
$raw = file_get_contents('php://input');
$payload = json_decode($raw !== false ? $raw : '', true);
$payload = is_array($payload) ? $payload : [];
$users = preg_split('/[\s,;]+/', (string) ($payload['users'] ?? '')) ?: [];
$groups = preg_split('/[\s,;]+/', (string) ($payload['groups'] ?? '')) ?: [];
$store->saveAuth([
'required' => (bool) ($payload['required'] ?? true),
'users' => array_values(array_filter(array_map('trim', $users))),
'groups' => array_values(array_filter(array_map('trim', $groups))),
]);
echo json_encode($store->loadAuth(), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES);
exit;
}
http_response_code(405);
echo json_encode(['error' => 'Methode nicht erlaubt.'], JSON_UNESCAPED_UNICODE);