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>
This commit is contained in:
baodev0
2026-10-12 15:53:43 +07:00
co-authored by Claude Opus 5.5
parent 823af4a56a
commit e888a6ed5d
33 changed files with 1022 additions and 52 deletions
@@ -9,6 +9,8 @@ use App\Http\Facade\SignRSA;
use App\Http\Services\Telegram;
use App\Models\Setting;
use App\Support\Cache\CacheKey;
use App\Support\PublicSetting;
use App\Support\Turnstile;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Cache;
@@ -39,6 +41,7 @@ class SettingController extends Controller
'data' => [
'setting' => $settingValue,
'smtp' => $smtpValue,
'turnstile' => Turnstile::forAdmin(),
],
]);
}
@@ -49,18 +52,9 @@ class SettingController extends Controller
*/
public function public(): JsonResponse
{
$setting = Setting::where('key', 'setting')->first();
$value = $setting ? json_decode((string) $setting->value, true) : [];
return response()->json([
'error' => false,
'data' => [
'title' => $value['title'] ?? '',
'company' => $value['company'] ?? '',
'logo' => $value['logo'] ?? '',
'favi_icon' => $value['favi_icon'] ?? '',
'brand_color' => $value['brand_color'] ?? '',
],
'data' => PublicSetting::values() + ['turnstile_site_key' => Turnstile::siteKey()],
]);
}
@@ -80,6 +74,10 @@ class SettingController extends Controller
'smtp.encryption' => 'sometimes|in:ssl,tls,starttls,',
'smtp.from_name' => 'sometimes|string|nullable',
'smtp.from_address' => 'sometimes|email|nullable',
'turnstile' => 'sometimes|array',
'turnstile.enabled' => 'sometimes|boolean',
'turnstile.site_key' => 'sometimes|string|nullable|max:255',
'turnstile.secret_key' => 'sometimes|string|nullable|max:255',
]);
if ($validator->fails()) {
@@ -120,6 +118,14 @@ class SettingController extends Controller
Cache::forget(CacheKey::build('settings', 'mail'));
}
if ($request->has('turnstile')) {
try {
Turnstile::save($request->input('turnstile'));
} catch (\InvalidArgumentException $e) {
return response()->json(['error' => true, 'message' => $e->getMessage()], 422);
}
}
return response()->json([
'error' => false,
'message' => 'Cập nhật cài đặt thành công.',