Rebuild
This commit is contained in:
@@ -13,6 +13,111 @@ function t(string $key, $default = '', array $vars = []): string
|
||||
return app()->i18n()->get($key, $default, $vars);
|
||||
}
|
||||
|
||||
function current_client_id(): string
|
||||
{
|
||||
$session = app()->session();
|
||||
$session->start();
|
||||
return $session->ensureClientId();
|
||||
}
|
||||
|
||||
function user_theme(): string
|
||||
{
|
||||
$pdo = app()->basePdo();
|
||||
if (!$pdo) {
|
||||
return 'light';
|
||||
}
|
||||
|
||||
$clientId = current_client_id();
|
||||
$stmt = $pdo->prepare("SELECT theme FROM nexus_user_prefs WHERE client_id = :id LIMIT 1");
|
||||
$stmt->execute(['id' => $clientId]);
|
||||
$row = $stmt->fetch(\PDO::FETCH_ASSOC);
|
||||
$theme = is_array($row) ? (string)($row['theme'] ?? '') : '';
|
||||
return $theme !== '' ? $theme : 'light';
|
||||
}
|
||||
|
||||
function set_user_theme(string $theme): void
|
||||
{
|
||||
$pdo = app()->basePdo();
|
||||
if (!$pdo) {
|
||||
return;
|
||||
}
|
||||
|
||||
$clientId = current_client_id();
|
||||
$stmt = $pdo->prepare(
|
||||
"INSERT INTO nexus_user_prefs (client_id, theme, updated_at)
|
||||
VALUES (:id, :theme, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(client_id) DO UPDATE SET
|
||||
theme = excluded.theme,
|
||||
updated_at = CURRENT_TIMESTAMP"
|
||||
);
|
||||
$stmt->execute(['id' => $clientId, 'theme' => $theme]);
|
||||
}
|
||||
|
||||
function current_module_name(): ?string
|
||||
{
|
||||
$path = app()->request()->path();
|
||||
if (preg_match('~^/module/([a-zA-Z0-9_-]+)~', $path, $m)) {
|
||||
return $m[1];
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
function auth_enabled(): bool
|
||||
{
|
||||
return app()->config()->authEnabled;
|
||||
}
|
||||
|
||||
function auth_user(): ?array
|
||||
{
|
||||
$session = app()->session();
|
||||
$session->start();
|
||||
return $_SESSION['auth_user'] ?? null;
|
||||
}
|
||||
|
||||
function auth_groups(): array
|
||||
{
|
||||
$user = auth_user();
|
||||
return is_array($user['groups'] ?? null) ? $user['groups'] : [];
|
||||
}
|
||||
|
||||
function auth_is_admin(): bool
|
||||
{
|
||||
$config = app()->config();
|
||||
$groups = auth_groups();
|
||||
return in_array($config->oidcAdminGroup, $groups, true);
|
||||
}
|
||||
|
||||
function auth_is_user(): bool
|
||||
{
|
||||
$config = app()->config();
|
||||
$groups = auth_groups();
|
||||
if (in_array($config->oidcAdminGroup, $groups, true)) {
|
||||
return true;
|
||||
}
|
||||
return in_array($config->oidcUserGroup, $groups, true);
|
||||
}
|
||||
|
||||
function require_auth(): void
|
||||
{
|
||||
if (!auth_enabled()) {
|
||||
return;
|
||||
}
|
||||
if (auth_user()) {
|
||||
return;
|
||||
}
|
||||
redirect('/auth/login');
|
||||
}
|
||||
|
||||
function require_admin(): void
|
||||
{
|
||||
require_auth();
|
||||
if (!auth_is_admin()) {
|
||||
http_response_code(403);
|
||||
echo '<div class="card">Keine Berechtigung.</div>';
|
||||
exit;
|
||||
}
|
||||
}
|
||||
|
||||
function modules(): \App\ModuleManager
|
||||
{
|
||||
return app()->modules();
|
||||
|
||||
Reference in New Issue
Block a user