src/Controller/RouteAuthController.php line 118

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\HistoriqueLogin;
  4. use App\Entity\User;
  5. use App\Wrappers\Bearer;
  6. use App\Wrappers\Cipher;
  7. use App\Wrappers\Scraping;
  8. use App\Wrappers\VazivaURL;
  9. use Doctrine\ORM\EntityManagerInterface;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Serializer\SerializerInterface;
  14. use Symfony\Component\Validator\Validator\ValidatorInterface;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Contracts\HttpClient\HttpClientInterface;
  17. class RouteAuthController extends AbstractController
  18. {
  19.     private $_em;
  20.     private $_serializer;
  21.     private $_validator;
  22.     private $_client;
  23.     public function __construct(EntityManagerInterface $emSerializerInterface $serializerValidatorInterface $validatorHttpClientInterface $client)
  24.     {
  25.         $this->_em $em;
  26.         $this->_serializer $serializer;
  27.         $this->_validator $validator;
  28.         $this->_client $client;
  29.     }
  30.     /**
  31.      * @Route("/log/two/auth", name="route_auth")
  32.      */
  33.     public function index(Request $req): Response
  34.     {
  35.         $token $req->headers->get("autorization");
  36.         //$token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2NDUxODI0MjMsImV4cCI6MTY0NTI2ODgyMywicm9sZXMiOlsiUk9MRV9VU0VSIl0sInVzZXJuYW1lIjoiZW1tYW51ZWxzaW1pc2lAZ21haWwuY29tIn0.L7j9yJq4cRlQeWu6uj3PJxH_qltel1e6nFbjAdxuIR-AcA2cc1fvLMRb25rGxn2WOzrHhOI94pV2Nm-INpsUHHFJxm1tbBTuuPtRleM2C3x525hQ9LymBQ6P8OzNawOjhU91mo1kIbPQg2wkQ3GLbfzaZtppEqjmSCTW1-Te3rRcNtOfdGdKjJWgZPMkMZZBuD5TeGggMaMOJgTlCWcTWM2nekqzPgGlTNI2kOyYfKmEum05gnnI5INMpznYJgCbftDfwBlw_sL0LtGHIZ7c311bzGbNjwZIZ1x8NUsejJWSAfT3KzuY_oXeRJTJ-haqf2DSjzEbMdXXhs2sVsjSTr5vsySt0sbWewUEv0ugZ__X4SD1mIJIAPXe5L9xA4bnO2RyOHZCa1rEOPBNLNVj6JsM5dyfYnmU2kKBKlhQQodtgeLtV8DMpApiTyrYLh22_iE2jzPw9aFSEho04eciLA-ElocwXUPWuF7eH8bpS4mlPVM4ZpMH57M6KUB9_ItI2qZ72P6-bhAbO0VFBhy0ko9LHE3fERumQIWWz1FIW6cmeFH9hEKF8adtrBMB7P4A2gZzl7jM2UKji7TdZXO15vpbRAXhFBWu8rFVcb3NghLJSF0YwUxYRRcy5JQZCg8pObITaTtsODjjS4fkYJHbONwhfV9ZCCVPUcwiIkoL_Z8";
  37.         if ($token) {
  38.             # code...
  39.             $user Bearer::Current_User($token$this->_em);
  40.             return $this->json($user);
  41.         }
  42.         return $this->render('route_auth/index.html.twig', [
  43.             'controller_name' => 'RouteAuthController',
  44.         ]);
  45.     }
  46.     /**
  47.      * @Route("/two/auth", methods={"POST"})
  48.      */
  49.     public function auth(Request $req)
  50.     {
  51.         $post $req->getContent();
  52.         $json json_decode($posttrue);
  53.         $code "";
  54.         $uid "";
  55.         $browser $_SERVER['HTTP_USER_AGENT'];
  56.         //$browser = get_browser(null, true);
  57.         //dd($browser);
  58.         $scrap Scraping::fetchGetInformation('GET''https://api.db-ip.com/v2/free/self'$this->_client);
  59.         if (isset($json['code'])) $code $json['code'];
  60.         # code...
  61.         if (isset($json["uid"])) $uid $json['uid'];
  62.         if (!$uid && !$code)
  63.             # code...
  64.             return $this->json(['Error']);
  65.         $user $this->_em->getRepository(User::class)->find(Cipher::Decrypt($uid));
  66.         if ($code === $user->getEmailAuthCode()) {
  67.             # code...
  68.             $user->setIsAuth(true);
  69.             $history = new HistoriqueLogin();
  70.             $history->setIpAdress($scrap['ipAddress']);
  71.             $history->setContinentCode($scrap['continentCode']);
  72.             $history->setContinentName($scrap['continentName']);
  73.             $history->setContryCode($scrap['countryCode']);
  74.             $history->setContryName($scrap['countryName']);
  75.             $history->setStateProv($scrap['stateProv']);
  76.             $history->setUser($user);
  77.             $this->_em->persist($history);
  78.             $this->_em->flush();
  79.             return $this->json(['status' => 201'message' => 'succes']);
  80.         }
  81.         return $this->json(['status' => 401'message' => 'error']);
  82.     }
  83.     /**
  84.      * @Route("/dash",name="dash")
  85.      * @Route("/", name="route_home")
  86.      * @Route("/reset", name="route_reset")
  87.      * @Route("/transactions/{id}", name="transactions",defaults={"id":"0"})
  88.      * @Route("/cartes", name="cartes")
  89.      * @Route("/document", name="route_publicites")
  90.      * @Route("/inscription", name="route_inscription")
  91.      * @Route("/historique/connexion", name="route_histo_connexion")
  92.      * @Route("/moncompte", name="route_compte")
  93.      * @Route("/faq", name="route_faq")
  94.      * @Route("/bonPlan", name="route_event")
  95.      * @Route("/profil", name="route_profil")
  96.      * @Route("/cartes/orderSuccess", name="route_carte_success")
  97.      * @Route("/formule",name="route_paypal")
  98.      * @Route("/service",name="route_security")
  99.      * @Route("/security",name="route_securityd")
  100.      * @Route("/parametre/carte",name="route_parametre_carte")
  101.      * @Route("/historique",name="route_commande_liste")
  102.      * @Route("/support",name="route_support")
  103.      * @Route("/requete",name="requetes")
  104.      * @Route("/confirmLogin",name="confirmLogin")
  105.      * @Route("/reset_password", name="resetPassword")
  106.      * @Route("/payement", name="paiement")
  107.      * @Route("/inscription_success",name="inscription_success")
  108.      */
  109.     public function home(): Response
  110.     {
  111.         return $this->render('route_auth/index.html.twig', [
  112.             'controller_name' => 'RouteAuthController',
  113.         ]);
  114.     }
  115.     /**
  116.      * @Route("/test",name="dassh")
  117.      */
  118.     public function cute(HttpClientInterface $client)
  119.     {
  120.         //dd($error);
  121.         $response $client->request('POST'VazivaURL::$REGISTER, [
  122.             'headers' => [
  123.                 'Content-Type' => 'application/json',
  124.                 'X-POS-CLIENT-KEY' => 'f3e067ce-bf93-418e-9fda-56bf1657dc93'
  125.             ],
  126.             'body' => ['mobilePhone' => '+212766742252''email' => '[email protected]''password' => 'password123'],
  127.         ]);
  128.         dd($response);
  129.         //dd($response);
  130.         $statusCode $response->getStatusCode();
  131.         // $statusCode = 200
  132.         $contentType $response->getHeaders()['content-type'][0];
  133.         // $contentType = 'application/json'
  134.         $content $response->getContent();
  135.         // $content = '{"id":521583, "name":"symfony-docs", ...}'
  136.         $content $response->toArray();
  137.         // $content = ['id' => 521583, 'name' => 'symfony-docs', ...]
  138.         //return $content;
  139.     }
  140.     /**
  141.      * @Route("/auth/login")
  142.      */
  143.     public function connex(Request $req)
  144.     {
  145.         $data $req->getContent();
  146.         $json json_decode($datatrue);
  147.         if (!isset($json['mobilePhone'])) return $this->json(['status' => 'Error''code' => 401]);
  148.         if (!isset($json["password"])) return $this->json(['status' => 'Error''code' => 401]);
  149.         $data = array(
  150.             'returnUrl' => 'https://127.0.0.1:8000/',
  151.             'mobilePhone' => $json['mobilePhone'],
  152.             'password' => $json['password']
  153.         );
  154.         //dd($data);
  155.         $reponse VazivaURL::FETCH_DATA(VazivaURL::$CONNEXIONjson_encode($data));
  156.         return $this->json(json_decode($reponse));
  157.     }
  158.     /**
  159.      * @Route("/reset/password")
  160.      */
  161.     public function resetPasse(Request $req)
  162.     {
  163.         $data $req->getContent();
  164.         $json json_decode($datatrue);
  165.         if (!isset($json['mobilePhone'])) return $this->json(['status' => 'Error''code' => 401]);
  166.         if (!isset($json["password"])) return $this->json(['status' => 'Error''code' => 401]);
  167.         $data = array(
  168.             'returnUrl' => 'https://127.0.0.1:8000/',
  169.             'mobilePhone' => $json['mobilePhone'],
  170.             'password' => $json['password']
  171.         );
  172.         //dd($data);
  173.         $reponse VazivaURL::FETCH_DATA(VazivaURL::$EMAIL_MPjson_encode($data));
  174.         return $this->json(json_decode($reponse));
  175.     }
  176. }