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:
co-authored by
Claude Opus 5.5
parent
823af4a56a
commit
e888a6ed5d
@@ -205,16 +205,16 @@ class ProductController extends Controller
|
||||
{
|
||||
$currency = $data['currency'] ?? 'VND';
|
||||
$cycles = [
|
||||
'monthly' => 'price_monthly',
|
||||
'quarterly' => 'price_quarterly',
|
||||
'semi_annually' => 'price_semiannually',
|
||||
'annually' => 'price_annually',
|
||||
'biennially' => 'price_biennially',
|
||||
'triennially' => 'price_triennially',
|
||||
'onetime' => 'price_onetime',
|
||||
'monthly' => ['price_monthly', []],
|
||||
'quarterly' => ['price_quarterly', []],
|
||||
'semi_annually' => ['price_semiannually', ['semiannually']],
|
||||
'annually' => ['price_annually', []],
|
||||
'biennially' => ['price_biennially', []],
|
||||
'triennially' => ['price_triennially', []],
|
||||
'onetime' => ['price_onetime', ['one_time']],
|
||||
];
|
||||
|
||||
foreach ($cycles as $cycle => $field) {
|
||||
foreach ($cycles as $cycle => [$field, $legacyCycles]) {
|
||||
if (!array_key_exists($field, $data)) {
|
||||
continue;
|
||||
}
|
||||
@@ -226,9 +226,12 @@ class ProductController extends Controller
|
||||
['product_id' => $product->id, 'billing_cycle' => $cycle],
|
||||
['price' => $price, 'currency' => $currency, 'is_active' => true]
|
||||
);
|
||||
ProductPricings::where('product_id', $product->id)
|
||||
->whereIn('billing_cycle', $legacyCycles)
|
||||
->delete();
|
||||
} else {
|
||||
ProductPricings::where('product_id', $product->id)
|
||||
->where('billing_cycle', $cycle)
|
||||
->whereIn('billing_cycle', [$cycle, ...$legacyCycles])
|
||||
->delete();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Controllers\Api\Admin\Setting;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Support\ClientMenu;
|
||||
use App\Support\ClientQuickLinks;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ClientMenuController extends Controller
|
||||
{
|
||||
public function show(): JsonResponse
|
||||
{
|
||||
return response()->json(['error' => false, 'data' => ClientMenu::items()]);
|
||||
}
|
||||
|
||||
public function update(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate(ClientMenu::rules());
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã lưu menu.',
|
||||
'data' => ClientMenu::save($validated['items']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function showQuickLinks(): JsonResponse
|
||||
{
|
||||
return response()->json(['error' => false, 'data' => ClientQuickLinks::items()]);
|
||||
}
|
||||
|
||||
public function updateQuickLinks(Request $request): JsonResponse
|
||||
{
|
||||
$validated = $request->validate(ClientQuickLinks::rules());
|
||||
|
||||
return response()->json([
|
||||
'error' => false,
|
||||
'message' => 'Đã lưu nút tắt.',
|
||||
'data' => ClientQuickLinks::save($validated['items']),
|
||||
]);
|
||||
}
|
||||
}
|
||||
@@ -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.',
|
||||
|
||||
Reference in New Issue
Block a user