src/Controller/Front/CheckIpController.php line 14

Open in your IDE?
  1. <?php
  2. namespace Acme\SudcmsBundle\Controller\Front;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\JsonResponse;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. class CheckIpController extends AbstractController
  8. {
  9.     #[Route(path'/check-ip'name'axCheckIp'methods: ['POST'])]
  10.     public function axCheckIp(Request $request): JsonResponse
  11.     {
  12.         if (defined('CURRENT_SITE_ID') && CURRENT_SITE_ID == 1) {
  13.             $data json_decode($request->getContent(), true);
  14.             if (!$data || !isset($data['ip'])) {
  15.                 return new JsonResponse([
  16.                     'status' => 'false',
  17.                 ]);
  18.             }
  19.             $clientIp $data['ip'];
  20.             $allowedIp = ['82.67.101.58''82.66.62.123''83.206.164.35'];
  21.             if (!in_array($clientIp$allowedIptrue)) {
  22.                 return new JsonResponse([
  23.                     'status' => 'false',
  24.                 ]);
  25.             }
  26.             return new JsonResponse([
  27.                 'status' => 'success',
  28.             ]);
  29.         }
  30.         return new JsonResponse([
  31.             'status' => 'success',
  32.         ]);
  33.     }
  34. }