<?php
namespace App\Controller;
use App\Entity\HistoriqueLogin;
use App\Entity\User;
use App\Wrappers\Bearer;
use App\Wrappers\Cipher;
use App\Wrappers\Scraping;
use App\Wrappers\VazivaURL;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Serializer\SerializerInterface;
use Symfony\Component\Validator\Validator\ValidatorInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Contracts\HttpClient\HttpClientInterface;
class RouteAuthController extends AbstractController
{
private $_em;
private $_serializer;
private $_validator;
private $_client;
public function __construct(EntityManagerInterface $em, SerializerInterface $serializer, ValidatorInterface $validator, HttpClientInterface $client)
{
$this->_em = $em;
$this->_serializer = $serializer;
$this->_validator = $validator;
$this->_client = $client;
}
/**
* @Route("/log/two/auth", name="route_auth")
*/
public function index(Request $req): Response
{
$token = $req->headers->get("autorization");
//$token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9.eyJpYXQiOjE2NDUxODI0MjMsImV4cCI6MTY0NTI2ODgyMywicm9sZXMiOlsiUk9MRV9VU0VSIl0sInVzZXJuYW1lIjoiZW1tYW51ZWxzaW1pc2lAZ21haWwuY29tIn0.L7j9yJq4cRlQeWu6uj3PJxH_qltel1e6nFbjAdxuIR-AcA2cc1fvLMRb25rGxn2WOzrHhOI94pV2Nm-INpsUHHFJxm1tbBTuuPtRleM2C3x525hQ9LymBQ6P8OzNawOjhU91mo1kIbPQg2wkQ3GLbfzaZtppEqjmSCTW1-Te3rRcNtOfdGdKjJWgZPMkMZZBuD5TeGggMaMOJgTlCWcTWM2nekqzPgGlTNI2kOyYfKmEum05gnnI5INMpznYJgCbftDfwBlw_sL0LtGHIZ7c311bzGbNjwZIZ1x8NUsejJWSAfT3KzuY_oXeRJTJ-haqf2DSjzEbMdXXhs2sVsjSTr5vsySt0sbWewUEv0ugZ__X4SD1mIJIAPXe5L9xA4bnO2RyOHZCa1rEOPBNLNVj6JsM5dyfYnmU2kKBKlhQQodtgeLtV8DMpApiTyrYLh22_iE2jzPw9aFSEho04eciLA-ElocwXUPWuF7eH8bpS4mlPVM4ZpMH57M6KUB9_ItI2qZ72P6-bhAbO0VFBhy0ko9LHE3fERumQIWWz1FIW6cmeFH9hEKF8adtrBMB7P4A2gZzl7jM2UKji7TdZXO15vpbRAXhFBWu8rFVcb3NghLJSF0YwUxYRRcy5JQZCg8pObITaTtsODjjS4fkYJHbONwhfV9ZCCVPUcwiIkoL_Z8";
if ($token) {
# code...
$user = Bearer::Current_User($token, $this->_em);
return $this->json($user);
}
return $this->render('route_auth/index.html.twig', [
'controller_name' => 'RouteAuthController',
]);
}
/**
* @Route("/two/auth", methods={"POST"})
*/
public function auth(Request $req)
{
$post = $req->getContent();
$json = json_decode($post, true);
$code = "";
$uid = "";
$browser = $_SERVER['HTTP_USER_AGENT'];
//$browser = get_browser(null, true);
//dd($browser);
$scrap = Scraping::fetchGetInformation('GET', 'https://api.db-ip.com/v2/free/self', $this->_client);
if (isset($json['code'])) $code = $json['code'];
# code...
if (isset($json["uid"])) $uid = $json['uid'];
if (!$uid && !$code)
# code...
return $this->json(['Error']);
$user = $this->_em->getRepository(User::class)->find(Cipher::Decrypt($uid));
if ($code === $user->getEmailAuthCode()) {
# code...
$user->setIsAuth(true);
$history = new HistoriqueLogin();
$history->setIpAdress($scrap['ipAddress']);
$history->setContinentCode($scrap['continentCode']);
$history->setContinentName($scrap['continentName']);
$history->setContryCode($scrap['countryCode']);
$history->setContryName($scrap['countryName']);
$history->setStateProv($scrap['stateProv']);
$history->setUser($user);
$this->_em->persist($history);
$this->_em->flush();
return $this->json(['status' => 201, 'message' => 'succes']);
}
return $this->json(['status' => 401, 'message' => 'error']);
}
/**
* @Route("/dash",name="dash")
* @Route("/", name="route_home")
* @Route("/reset", name="route_reset")
* @Route("/transactions/{id}", name="transactions",defaults={"id":"0"})
* @Route("/cartes", name="cartes")
* @Route("/document", name="route_publicites")
* @Route("/inscription", name="route_inscription")
* @Route("/historique/connexion", name="route_histo_connexion")
* @Route("/moncompte", name="route_compte")
* @Route("/faq", name="route_faq")
* @Route("/bonPlan", name="route_event")
* @Route("/profil", name="route_profil")
* @Route("/cartes/orderSuccess", name="route_carte_success")
* @Route("/formule",name="route_paypal")
* @Route("/service",name="route_security")
* @Route("/security",name="route_securityd")
* @Route("/parametre/carte",name="route_parametre_carte")
* @Route("/historique",name="route_commande_liste")
* @Route("/support",name="route_support")
* @Route("/requete",name="requetes")
* @Route("/confirmLogin",name="confirmLogin")
* @Route("/reset_password", name="resetPassword")
* @Route("/payement", name="paiement")
* @Route("/inscription_success",name="inscription_success")
*/
public function home(): Response
{
return $this->render('route_auth/index.html.twig', [
'controller_name' => 'RouteAuthController',
]);
}
/**
* @Route("/test",name="dassh")
*/
public function cute(HttpClientInterface $client)
{
//dd($error);
$response = $client->request('POST', VazivaURL::$REGISTER, [
'headers' => [
'Content-Type' => 'application/json',
'X-POS-CLIENT-KEY' => 'f3e067ce-bf93-418e-9fda-56bf1657dc93'
],
'body' => ['mobilePhone' => '+212766742252', 'email' => '[email protected]', 'password' => 'password123'],
]);
dd($response);
//dd($response);
$statusCode = $response->getStatusCode();
// $statusCode = 200
$contentType = $response->getHeaders()['content-type'][0];
// $contentType = 'application/json'
$content = $response->getContent();
// $content = '{"id":521583, "name":"symfony-docs", ...}'
$content = $response->toArray();
// $content = ['id' => 521583, 'name' => 'symfony-docs', ...]
//return $content;
}
/**
* @Route("/auth/login")
*/
public function connex(Request $req)
{
$data = $req->getContent();
$json = json_decode($data, true);
if (!isset($json['mobilePhone'])) return $this->json(['status' => 'Error', 'code' => 401]);
if (!isset($json["password"])) return $this->json(['status' => 'Error', 'code' => 401]);
$data = array(
'returnUrl' => 'https://127.0.0.1:8000/',
'mobilePhone' => $json['mobilePhone'],
'password' => $json['password']
);
//dd($data);
$reponse = VazivaURL::FETCH_DATA(VazivaURL::$CONNEXION, json_encode($data));
return $this->json(json_decode($reponse));
}
/**
* @Route("/reset/password")
*/
public function resetPasse(Request $req)
{
$data = $req->getContent();
$json = json_decode($data, true);
if (!isset($json['mobilePhone'])) return $this->json(['status' => 'Error', 'code' => 401]);
if (!isset($json["password"])) return $this->json(['status' => 'Error', 'code' => 401]);
$data = array(
'returnUrl' => 'https://127.0.0.1:8000/',
'mobilePhone' => $json['mobilePhone'],
'password' => $json['password']
);
//dd($data);
$reponse = VazivaURL::FETCH_DATA(VazivaURL::$EMAIL_MP, json_encode($data));
return $this->json(json_decode($reponse));
}
}