feat: implement server-side validation for mobile numbers and national codes across multiple endpoints
This commit is contained in:
@@ -4,6 +4,7 @@ namespace App\Admin\Controller;
|
||||
|
||||
use App\Appointment\Entity\Appointment;
|
||||
use App\Auth\Entity\User;
|
||||
use App\Shared\Service\InputValidator;
|
||||
use App\Location\Entity\City;
|
||||
use App\Clinic\Entity\Clinic;
|
||||
use App\Doctor\Entity\Doctor;
|
||||
@@ -381,12 +382,15 @@ class AdminApiController extends BaseController
|
||||
public function createDoctor(Request $request): JsonResponse
|
||||
{
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
$mobile = trim((string) ($data['mobile'] ?? ''));
|
||||
$mobile = InputValidator::toEnglishDigits(trim((string) ($data['mobile'] ?? '')));
|
||||
$name = trim((string) ($data['name'] ?? ''));
|
||||
|
||||
if ($mobile === '' || $name === '') {
|
||||
return $this->error('VALIDATION', 'موبایل و نام الزامی هستند', 422);
|
||||
}
|
||||
if (!InputValidator::isValidIranMobile($mobile)) {
|
||||
return $this->error('VALIDATION', 'شماره موبایل نامعتبر است', 422, 'mobile');
|
||||
}
|
||||
|
||||
$user = $this->em->getRepository(User::class)->findOneBy(['mobileNumber' => $mobile]);
|
||||
if (!$user) {
|
||||
@@ -491,12 +495,15 @@ class AdminApiController extends BaseController
|
||||
public function createClinic(Request $request): JsonResponse
|
||||
{
|
||||
$data = json_decode($request->getContent(), true) ?? [];
|
||||
$mobile = trim((string) ($data['owner_mobile'] ?? ''));
|
||||
$mobile = InputValidator::toEnglishDigits(trim((string) ($data['owner_mobile'] ?? '')));
|
||||
$name = trim((string) ($data['name'] ?? ''));
|
||||
|
||||
if ($mobile === '') {
|
||||
return $this->error('VALIDATION', 'شماره موبایل الزامی است', 422);
|
||||
}
|
||||
if (!InputValidator::isValidIranMobile($mobile)) {
|
||||
return $this->error('VALIDATION', 'شماره موبایل نامعتبر است', 422, 'owner_mobile');
|
||||
}
|
||||
if ($name === '') {
|
||||
return $this->error('VALIDATION', 'نام کلینیک الزامی است', 422);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user