Files
portal-api/app/Support/ClientQuickLinks.php
T
baodev0andClaude Opus 5.5 e888a6ed5d feat: Turnstile captcha, menu khách + nút tắt topbar cấu hình từ admin, ẩn setting nhạy cảm
- Turnstile (App\Support\Turnstile, middleware turnstile) cho login admin và login/register/forgot/reset của khách; cấu hình ở setting key=turnstile, secret mã hoá SignRSA.
- Menu sidebar khách (setting client_menu) và nút tắt topbar (setting client_quick_links) do admin sửa qua administrator/client-menu[/quick-links], khách đọc v1/setting/menu, v1/setting/quick-links.
- v1/setting và settings/public chỉ trả whitelist PublicSetting::FIELDS (trước đây lộ bot_token, inet_api_key).
- Cài đặt tài khoản khách (preferences), rate limit theo IP cho register/resend-verify.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-12 15:53:43 +07:00

50 lines
1.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Support;
use App\Models\Setting;
final class ClientQuickLinks
{
public const SETTING_KEY = 'client_quick_links';
/**
* @return list<array{title: string, icon: ?string, href: string, disabled: bool}>
*/
public static function items(): array
{
$value = json_decode((string) Setting::where('key', self::SETTING_KEY)->value('value'), true);
return is_array($value) ? $value : [];
}
/**
* @return array<string, mixed>
*/
public static function rules(): array
{
return [
'items' => 'present|array|max:6',
'items.*' => 'array',
'items.*.title' => 'required|string|max:40',
'items.*.icon' => ['nullable', 'string', 'max:100', 'regex:' . ClientMenu::ICON_PATTERN],
'items.*.href' => ['required', 'string', 'max:255', 'regex:' . ClientMenu::HREF_PATTERN],
'items.*.disabled' => 'sometimes|boolean',
];
}
/**
* @param array<int, array<string, mixed>> $items
*/
public static function save(array $items): array
{
$normalized = array_map(ClientMenu::normalizeLink(...), array_values($items));
Setting::updateOrCreate(['key' => self::SETTING_KEY], ['value' => json_encode($normalized, JSON_UNESCAPED_UNICODE)]);
return $normalized;
}
}