src/Controller/AuthenticationController.php line 17
<?phpnamespace App\Controller;use App\Entity\Log;use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;use Symfony\Component\HttpFoundation\Response;use Symfony\Component\Routing\Annotation\Route;use Symfony\Component\HttpFoundation\Request;use Doctrine\ORM\EntityManagerInterface;use Symfony\Component\HttpFoundation\Session\Session;class AuthenticationController extends AbstractController{#[Route('/authentication', name: 'app_authentication')]public function login(Request $request, Session $session, EntityManagerInterface $entityManager): Response{if ($request->request->count() > 0) {$phone = $request->request->get("phone");$password = $request->request->get("password");$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/login");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, '{"username" : "' . $phone . '","password" : "' . $password . '"}');$headers = array("Content-Type: application/json","Accept: application/json",);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//for debug only!curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close($ch);$resp = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);// dd($resp);if ($resp == null) {$this->addFlash('NotifErrors', "Connexion avec l'api interrompu");$iduser = null;$idclient = null;$action = "Authentification";$msg_send = "Connexion";$msg_get = "Connexion avec l'api interrompu.";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_authentication');} else {if ($resp['statut'] == 201) {$error = $session->get('message', $resp['message']);$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Authentification";$msg_send = "Connexion";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_authentication');} else {if ($resp['statut'] == 400) {$error = $session->get('message', $resp['message']);$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Authentification";$msg_send = "Connexion";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_authentication');} else {if ($resp['statut'] == 200) {$session->start();$iduser = null;$idclient = null;$action = "Authentification";$msg_send = "Connexion";$msg_get = "Connexion reussie";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();// set and get session attributes$session->set('client', $resp['client']);$session->set('token', $resp['token']);$idClient = $session->set('idClient', $resp['client']['id']);return $this->redirectToRoute('app_assurance_auto');}}}}}return $this->render('authentication/login.html.twig', ['messageErr' => '',]);}#[Route('/logout', name: 'app_logout')]public function logout(EntityManagerInterface $em, Session $session): Response{$session->clear();return $this->redirectToRoute('app_home');}#[Route('/register', name: 'app_register')]public function register(Request $request, Session $session, EntityManagerInterface $entityManager,): Response{$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/client/typeClient");$headers = array("Content-Type: application/json","Accept: application/json",);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//for debug only!curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close($ch);$typeClients = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);if ($request->request->count() > 0) {// $typeClient = $request->request->get("typeClient");$nom = $request->request->get("firstname");$prenom = $request->request->get("lastname");$telephone = $request->request->get("phone");$motdepasse = $request->request->get("motDePasse");$motdepasse2 = $request->request->get("motDePasse2");$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/client");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, '{"nom" : "' . $nom . '","prenom" : "' . $prenom . '","telephone" : "' . $telephone . '","password" : "' . $motdepasse . '","password2" : "' . $motdepasse2 . '"}');$headers = array("Content-Type: application/json","Accept: application/json",);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//for debug only!curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close($ch);$resp = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);if ($resp == null) {$this->addFlash('message', "Connexion avec l'api interrompu");$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = "Connexion avec l'api interrompu";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 400) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 401) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 402) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 403) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 404) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 405) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 406) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 407) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 408) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 409) {$error = $session->get('message', $resp['message']);$this->addFlash('warning', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_register');} else {if ($resp['statut'] == 200) {$success = $session->get('message', $resp['message']);$iduser = null;$idclient = null;$action = "Creation compte client";$msg_send = "Creation";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();// $this->addFlash('success',$resp['message']);return $this->redirectToRoute('app_authentication');}}}}}}}}}}}}}return $this->render('authentication/register.html.twig', ['typeClients' => $typeClients['typeClients'],]);}#[Route('/changePassword', name: 'app_changePassword')]public function app_changePassword(Request $request, EntityManagerInterface $entityManager): Response{return $this->render('authentication/changePassword.html.twig', []);}#[Route('/sendCode', name: 'app_sendCode', methods: ['POST','GET'])]public function app_sendCode(Request $request, EntityManagerInterface $entityManager, Session $session): Response{if ($request->request->count() > 0) {$phone = $request->request->get("phone");$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/getnewpassword");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, '{"username" : "' . $phone . '"}');$headers = array("Content-Type: application/json","Accept: application/json",);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//for debug only!curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close($ch);$resp = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);// dd($resp);if ($resp == null) {$this->addFlash('NotifErrors', "Connexion avec l'api interrompu");$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Envoi code";$msg_get = "Connexion avec l'api interrompu.";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_sendCode');}elseif($resp['retour'] == 201){$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Envoi code";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_sendCode');}elseif ($resp['retour'] == 400){$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Envoi code";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_sendCode');}elseif ($resp['retour'] == 200){$this->addFlash('CodeEnvoyer', 'Le code de vérification a été envoyer avec succés');$session->start();$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Envoi Code ";$msg_get = "Envoi code reussie";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();// set and get session attributes$session->set('phone', $phone);return $this->redirectToRoute('app_confirmCode');}}return $this->redirectToRoute('app_changePassword');}#[Route('/confirmCode', name: 'app_confirmCode', methods: ['POST','GET'])]public function app_confirmCode(Request $request, EntityManagerInterface $entityManager, Session $session): Response{if ($request->request->count() > 0) {$phone = $session->get('phone');$code = $request->request->get("code");// dd($phone, $code);$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/confirmationCode");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, '{"telephone" : "' . $phone . '","code" : "' . $code . '"}');$headers = array("Content-Type: application/json","Accept: application/json",);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//for debug only!curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close($ch);$resp = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);// dd($resp);if ($resp == null) {$this->addFlash('NotifErrors', "Connexion avec l'api interrompu");$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Confirmation code";$msg_get = "Connexion avec l'api interrompu.";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_confirmCode');}elseif($resp['retour'] == 201){$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Confirmation code";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_confirmCode');}elseif ($resp['retour'] == 400){$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Confirmation code";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_confirmCode');}elseif ($resp['retour'] == 200){$this->addFlash('CodeExact', 'Le code de vérification est valide');$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Confirmation code ";$msg_get = "Confirmation code avec succès";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();// set and get session attributes$session->set('code', $code);return $this->redirectToRoute('app_changePassword_code');}}return $this->render('authentication/confirmCode.html.twig', []);}#[Route('/changePassword_Code', name: 'app_changePassword_code', methods: ['POST','GET'])]public function app_changePassword_Code(Request $request, EntityManagerInterface $entityManager, Session $session): Response{if ($request->request->count() > 0) {$phone = $session->get('phone');$code = $session->get("code");$password = $request->request->get("password");$confirmPassword = $request->request->get("confirm-password");// dd($phone, $code, $password, $confirmPassword);if ($password != $confirmPassword) {$this->addFlash('pasIdentiques', 'Les 2 mots de passe saisis ne sont pas identiques');return $this->redirectToRoute('app_changePassword_code');}$ch = curl_init();curl_setopt($ch, CURLOPT_URL, "https://carenapi235679814.caren-niger.com/api/Changepasswordforget");curl_setopt($ch, CURLOPT_POST, 1);curl_setopt($ch, CURLOPT_POSTFIELDS, '{"telephone" : "' . $phone . '","code" : "' . $code . '","pass" : "' . $password . '"}');$headers = array("Content-Type: application/json","Accept: application/json",);curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);//for debug only!curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);$server_output = curl_exec($ch);curl_close($ch);$resp = json_decode(preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $server_output), true);// dd($resp);if ($resp == null) {$this->addFlash('NotifErrors', "Connexion avec l'api interrompu");$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Changement de mot de passe";$msg_get = "Connexion avec l'api interrompu.";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_changePassword_code');}elseif($resp['retour'] == 201){$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Changement de mot de passe";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_changePassword_code');}elseif ($resp['retour'] == 400){$this->addFlash('NotifErrors', $resp['message']);$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Changement de mot de passe";$msg_get = $resp['message'];$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();return $this->redirectToRoute('app_changePassword_code');}elseif ($resp['retour'] == 200){$iduser = null;$idclient = null;$action = "Mot de passe oublié";$msg_send = "Changement de mot de passe";$msg_get = "Le mot de passe a été changer avec succès";$log = $this->log($action, $msg_send, $msg_get, $iduser,$idclient);$entityManager->persist($log);$entityManager->flush();$session->clear();$this->addFlash('success', 'Le mot de passe a été changer avec succès');return $this->redirectToRoute('app_authentication');}}return $this->render('authentication/changePasswordCode.html.twig', []);}public function log($action, $msg_send, $msg_get, $iduser, $idclient){$log = new Log();$date = new \DateTime('now');$ip = $_SERVER['REMOTE_ADDR'];if($iduser){$log->setUser($iduser);}if($idclient){$log->setClient($idclient);}$log->setAction($action);$log->setDate($date);$log->setIp($ip);$log->setCanal("web");$log->setMsgSend($msg_send);$log->setMsgGet($msg_get);return $log;}}