Files
portal-api/app/Http/Resources/Api/Client/ClientResource.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

77 lines
2.9 KiB
PHP

<?php
namespace App\Http\Resources\Api\Client;
use App\Services\Api\ServiceClient\ServiceClientService;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
class ClientResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
if (!$this->resource) {
return [];
}
return [
'customer' => [
'fullname' => $this->fullname,
'email' => $this->email,
'phone' => $this->phone,
'address' => $this->address,
'city' => $this->city,
'ward' => $this->ward->name ?? '',
'province' => $this->province->name ?? '',
'gender' => $this->gender_label,
'date' => $this->created_at ? $this->created_at->format('Y-m-d H:i:s') : null,
'company' => $this->company ?? '',
'avatar' => $this->avatar,
'cmnd_before' => $this->cccdUrl('front', $this->front_identity_number),
'cmnd_after' => $this->cccdUrl('back', $this->back_identity_number),
'cmnd' => $this->identity_number ? Str::mask($this->identity_number, '*', 0, -4) : null,
'fb_link' => null,
'active_2fa' => 0,
'off_mail_marketing' => $this->off_mail_marketing,
'email_marketing' => (bool) $this->email_marketing,
'receive_deposit' => (bool) $this->receive_deposit,
'is_recharge_zalo' => 0,
'is_verify_telegram' => 0,
],
'credit' => [
'credit' => $this->credit,
'total' => $this->total,
'total_pending' => $this->total_pending ?? 0,
'point' => $this->point,
'point_used' => 0,
'point_total' => $this->point,
],
'service' => [
'proxy' => 0,
...app(ServiceClientService::class)->countByType((int) $this->id),
]
];
}
/**
* Ảnh CCCD trên disk private → URL ký tương đối (/v1/client/cccd/...), hết hạn 60 phút.
*/
private function cccdUrl(string $side, ?string $path): string
{
if (!$path) {
return '';
}
// Giá trị import từ portal cũ (/uploads/... trên host cũ) cũng chỉ trả URL ký — không lộ đường dẫn gốc;
// route trả 404 cho chúng vì file không có trên disk private. Vẫn khác rỗng để hasCccd giữ nguyên hành vi.
return URL::temporarySignedRoute('api.client.cccd', now()->addHour(), ['customer' => $this->id, 'side' => $side], false);
}
}