Files
reflector-dashboard/auth/theme_prefs_update.php
T
bjorneandClaude Fable 5.1 25b481e2ae Public web-only release: SvxPortal front-end + auth backend, install templates and INSTALL.md
Stripped from the internal repo: per-box deploy trees, Go services (nodelist/astmeta/proxy/svxdr),
deploy/sync scripts and all secrets. Config templates for nginx, PHP-FPM, Redis and tmpfiles
live in install/ with CHANGEME placeholders.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-26 23:07:05 +02:00

52 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
require __DIR__ . '/lib.php';
// Per-account web theme preference (so a signed-in operator's theme follows them
// across devices/browsers). Stored on the account hash — me.php returns the whole
// hash, so 'web_theme' + 'web_theme_colors' surface there automatically.
// web_theme: 'dark' | 'light' | 'color'
// web_theme_colors: compact JSON { bg,panel,fg,fg2,line,accent } of #hex values
// Anonymous visitors never reach this endpoint — they use localStorage only.
$uuid = require_login();
csrf_check();
$j = json_in();
$updated = [];
if (array_key_exists('theme', $j)) {
$t = is_string($j['theme']) ? strtolower(trim($j['theme'])) : '';
if (!in_array($t, ['dark', 'light', 'color'], true)) {
json_out(['ok' => false, 'error' => 'invalid_theme', 'allowed' => ['dark', 'light', 'color']], 400);
}
redis()->hSet(acct_key($uuid), 'web_theme', $t);
$updated['web_theme'] = $t;
}
if (array_key_exists('colors', $j)) {
$c = $j['colors'];
$allow = ['bg', 'panel', 'fg', 'fg2', 'line', 'accent'];
$clean = [];
if (is_array($c)) {
foreach ($allow as $k) {
if (isset($c[$k]) && is_string($c[$k]) && preg_match('/^#[0-9a-fA-F]{3,8}$/', $c[$k])) {
$clean[$k] = strtolower($c[$k]);
}
}
}
// Cast to object so an empty selection serialises as '{}', never '[]'.
$json = json_encode((object)$clean, JSON_UNESCAPED_SLASHES);
if ($json === false || strlen($json) > 500) {
json_out(['ok' => false, 'error' => 'invalid_colors'], 400);
}
redis()->hSet(acct_key($uuid), 'web_theme_colors', $json);
$updated['web_theme_colors'] = $clean;
}
if (empty($updated)) {
json_out(['ok' => false, 'error' => 'nothing_to_update'], 400);
}
json_out(['ok' => true, 'updated' => $updated]);