feat: Persian panel/API fixes and structural-model tweaks
- lang/fa: add validation/auth/passwords/pagination translations so admin and API validation errors are in Persian - templates: soft-delete instead of cascade-deleting their generations; keep resolving trashed template on generations (labels/downloads) - templates: add TemplateInfolist with a real thumbnail ImageEntry - generations: auto-name template-based generations and use that name for the download file and as a searchable column - admin: show all dates as Jalali via ->jalaliDate()/->jalaliDateTime() Filament macros (App\Support\Jalali) - wallets: harden the deposit/withdraw action to surface the exact error instead of a 500 - profile: normalize Iranian mobile numbers (App\Support\Mobile), add social_links, coerce notification-preference booleans, require the current password to delete an account Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013P66ea1dC5CVM9t29496t5
This commit is contained in:
@@ -18,6 +18,6 @@ class GenerationDownloadController extends Controller
|
||||
abort_unless($user && ($user->hasRole('admin') || $user->hasPermission('templates.manage')), 403);
|
||||
abort_if($generation->status !== TemplateGenerationStatus::Completed || ! $generation->output_path, 404);
|
||||
|
||||
return Storage::disk('local')->download($generation->output_path, $generation->template->slug.'.pptx');
|
||||
return Storage::disk('local')->download($generation->output_path, $generation->downloadFilename().'.pptx');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace App\Http\Controllers\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Profile\ChangePasswordRequest;
|
||||
use App\Http\Requests\Profile\DeleteAccountRequest;
|
||||
use App\Http\Requests\Profile\UpdateProfileRequest;
|
||||
use App\Http\Resources\UserResource;
|
||||
use App\Traits\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use OpenApi\Attributes as OA;
|
||||
|
||||
@@ -158,10 +158,19 @@ class ProfileController extends Controller
|
||||
|
||||
#[OA\Delete(
|
||||
path: '/profile',
|
||||
description: 'Delete the authenticated user account',
|
||||
description: 'Delete the authenticated user account. Requires the current password for confirmation.',
|
||||
summary: 'Delete account',
|
||||
security: [['sanctum' => []]],
|
||||
tags: ['Profile'],
|
||||
requestBody: new OA\RequestBody(
|
||||
required: true,
|
||||
content: new OA\JsonContent(
|
||||
required: ['password'],
|
||||
properties: [
|
||||
new OA\Property(property: 'password', type: 'string', format: 'password', example: 'password123'),
|
||||
]
|
||||
)
|
||||
),
|
||||
responses: [
|
||||
new OA\Response(
|
||||
response: 200,
|
||||
@@ -176,10 +185,14 @@ class ProfileController extends Controller
|
||||
new OA\Response(response: 401, description: 'Unauthenticated'),
|
||||
]
|
||||
)]
|
||||
public function destroy(Request $request): JsonResponse
|
||||
public function destroy(DeleteAccountRequest $request): JsonResponse
|
||||
{
|
||||
$user = $request->user();
|
||||
|
||||
if ($user->avatar_path) {
|
||||
Storage::disk('public')->delete($user->avatar_path);
|
||||
}
|
||||
|
||||
$user->tokens()->delete();
|
||||
$user->delete();
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ use App\Http\Resources\TemplateGenerationResource;
|
||||
use App\Jobs\GenerateTemplateJob;
|
||||
use App\Models\Template;
|
||||
use App\Models\TemplateGeneration;
|
||||
use App\Support\Jalali;
|
||||
use App\Traits\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
@@ -80,6 +81,7 @@ class TemplateGenerationController extends Controller
|
||||
$generation = TemplateGeneration::query()->create([
|
||||
'template_id' => $template->id,
|
||||
'uuid' => $uuid,
|
||||
'title' => $this->buildGenerationTitle($template, $request),
|
||||
'status' => TemplateGenerationStatus::Pending,
|
||||
'values' => $storedValues,
|
||||
'requested_by' => $request->user()->id,
|
||||
@@ -264,6 +266,13 @@ class TemplateGenerationController extends Controller
|
||||
abort_if($generation->requested_by !== request()->user()->id, Response::HTTP_FORBIDDEN);
|
||||
abort_if($generation->status !== TemplateGenerationStatus::Completed || ! $generation->output_path, Response::HTTP_NOT_FOUND);
|
||||
|
||||
return Storage::disk('local')->download($generation->output_path, $generation->template->slug.'.pptx');
|
||||
return Storage::disk('local')->download($generation->output_path, $generation->downloadFilename().'.pptx');
|
||||
}
|
||||
|
||||
private function buildGenerationTitle(Template $template, Request $request): string
|
||||
{
|
||||
$label = $request->user()?->name ?: 'کاربر';
|
||||
|
||||
return sprintf('%s - %s - %s', $template->title, $label, Jalali::date(now()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,23 +6,57 @@ use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdateNotificationPreferencesRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* @var list<string>
|
||||
*/
|
||||
private const FIELDS = [
|
||||
'comment_on_presentation',
|
||||
'form_reply',
|
||||
'new_follower',
|
||||
'news_announcements',
|
||||
'weekly_product_updates',
|
||||
'weekly_blog_digest',
|
||||
];
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Accept "true"/"false"/"1"/"0"/1/0 strings from the frontend and coerce them to
|
||||
* real booleans before validation so the toggles actually persist.
|
||||
*/
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
$normalized = [];
|
||||
|
||||
foreach (self::FIELDS as $field) {
|
||||
if ($this->has($field)) {
|
||||
$normalized[$field] = filter_var($this->input($field), FILTER_VALIDATE_BOOL, FILTER_NULL_ON_FAILURE) ?? false;
|
||||
}
|
||||
}
|
||||
|
||||
if ($normalized !== []) {
|
||||
$this->merge($normalized);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return array_fill_keys(self::FIELDS, ['sometimes', 'boolean']);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'comment_on_presentation' => ['sometimes', 'boolean'],
|
||||
'form_reply' => ['sometimes', 'boolean'],
|
||||
'new_follower' => ['sometimes', 'boolean'],
|
||||
'news_announcements' => ['sometimes', 'boolean'],
|
||||
'weekly_product_updates' => ['sometimes', 'boolean'],
|
||||
'weekly_blog_digest' => ['sometimes', 'boolean'],
|
||||
'*.boolean' => 'مقدار این تنظیم باید بله یا خیر باشد.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests\Auth;
|
||||
|
||||
use App\Support\Mobile;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class RegisterRequest extends FormRequest
|
||||
@@ -11,6 +12,13 @@ class RegisterRequest extends FormRequest
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('mobile')) {
|
||||
$this->merge(['mobile' => Mobile::normalize($this->input('mobile'))]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
@@ -18,7 +26,7 @@ class RegisterRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'mobile' => ['required', 'string', 'regex:/^09\d{9}$/', 'unique:users,mobile'],
|
||||
'mobile' => ['required', 'string', 'regex:'.Mobile::REGEX, 'unique:users,mobile'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users,email'],
|
||||
'password' => ['required', 'string', 'min:8'],
|
||||
];
|
||||
@@ -32,7 +40,7 @@ class RegisterRequest extends FormRequest
|
||||
return [
|
||||
'name.required' => 'نام و نام خانوادگی الزامی است.',
|
||||
'mobile.required' => 'شماره موبایل الزامی است.',
|
||||
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست.',
|
||||
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789',
|
||||
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
|
||||
'email.required' => 'ایمیل الزامی است.',
|
||||
'email.email' => 'فرمت ایمیل صحیح نیست.',
|
||||
|
||||
34
app/Http/Requests/Profile/DeleteAccountRequest.php
Normal file
34
app/Http/Requests/Profile/DeleteAccountRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests\Profile;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class DeleteAccountRequest extends FormRequest
|
||||
{
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'password' => ['required', 'string', 'current_password'],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, string>
|
||||
*/
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'password.required' => 'برای حذف حساب کاربری، وارد کردن رمز عبور الزامی است.',
|
||||
'password.current_password' => 'رمز عبور واردشده صحیح نیست.',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Http\Requests\Profile;
|
||||
|
||||
use App\Support\Mobile;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
@@ -12,6 +13,13 @@ class UpdateProfileRequest extends FormRequest
|
||||
return true;
|
||||
}
|
||||
|
||||
protected function prepareForValidation(): void
|
||||
{
|
||||
if ($this->has('mobile')) {
|
||||
$this->merge(['mobile' => Mobile::normalize($this->input('mobile'))]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
@@ -23,10 +31,16 @@ class UpdateProfileRequest extends FormRequest
|
||||
'name' => ['sometimes', 'required', 'string', 'max:255'],
|
||||
'username' => ['sometimes', 'required', 'string', 'max:255', Rule::unique('users', 'username')->ignore($userId)],
|
||||
'email' => ['sometimes', 'required', 'string', 'email', 'max:255', Rule::unique('users', 'email')->ignore($userId)],
|
||||
'mobile' => ['sometimes', 'required', 'string', 'regex:/^09\d{9}$/', Rule::unique('users', 'mobile')->ignore($userId)],
|
||||
'mobile' => ['sometimes', 'required', 'string', 'regex:'.Mobile::REGEX, Rule::unique('users', 'mobile')->ignore($userId)],
|
||||
'password' => ['sometimes', 'required', 'string', 'min:8'],
|
||||
'avatar' => ['sometimes', 'nullable', 'image', 'max:3072'],
|
||||
'is_public' => ['sometimes', 'nullable', 'boolean'],
|
||||
'social_links' => ['sometimes', 'nullable', 'array'],
|
||||
'social_links.instagram' => ['nullable', 'string', 'max:255'],
|
||||
'social_links.telegram' => ['nullable', 'string', 'max:255'],
|
||||
'social_links.linkedin' => ['nullable', 'string', 'max:255'],
|
||||
'social_links.twitter' => ['nullable', 'string', 'max:255'],
|
||||
'social_links.website' => ['nullable', 'string', 'max:255'],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -43,12 +57,13 @@ class UpdateProfileRequest extends FormRequest
|
||||
'email.email' => 'فرمت ایمیل صحیح نیست.',
|
||||
'email.unique' => 'این ایمیل قبلاً ثبت شده است.',
|
||||
'mobile.required' => 'شماره موبایل الزامی است.',
|
||||
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست.',
|
||||
'mobile.regex' => 'فرمت شماره موبایل صحیح نیست. مثال درست: 09123456789',
|
||||
'mobile.unique' => 'این شماره موبایل قبلاً ثبت شده است.',
|
||||
'password.required' => 'رمز عبور الزامی است.',
|
||||
'password.min' => 'رمز عبور باید حداقل ۸ کاراکتر باشد.',
|
||||
'avatar.image' => 'فایل ارسالی باید تصویر باشد.',
|
||||
'avatar.max' => 'حداکثر حجم تصویر ۳ مگابایت است.',
|
||||
'social_links.array' => 'ساختار شبکههای اجتماعی نامعتبر است.',
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ use OpenApi\Attributes as OA;
|
||||
new OA\Property(property: 'mobile', type: 'string', example: '09123456789'),
|
||||
new OA\Property(property: 'avatar_url', type: 'string', example: 'https://example.com/storage/avatars/1.png', nullable: true),
|
||||
new OA\Property(property: 'is_public', type: 'boolean', example: false),
|
||||
new OA\Property(property: 'social_links', type: 'object', example: ['instagram' => 'https://instagram.com/handle'], nullable: true),
|
||||
new OA\Property(property: 'created_at', type: 'string', format: 'date-time'),
|
||||
]
|
||||
)]
|
||||
@@ -37,6 +38,7 @@ class UserResource extends JsonResource
|
||||
'mobile' => $this->mobile,
|
||||
'avatar_url' => $this->avatar_path ? Storage::disk('public')->url($this->avatar_path) : null,
|
||||
'is_public' => $this->is_public,
|
||||
'social_links' => $this->social_links ?: null,
|
||||
'created_at' => $this->created_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user