src/Controller/SecurityController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\Routing\Annotation\Route;
  7. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  8. use Symfony\Component\Security\Http\LoginLink\LoginLinkHandlerInterface;
  9. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  10. use App\Entity\User;
  11. use App\Utilities\Utilities;
  12. class SecurityController extends AbstractController {
  13.     public function login(AuthenticationUtils $authenticationUtils): Response {
  14.         if ($this->getUser()) {
  15.             return $this->redirectToRoute('app_home');
  16.         }
  17.         // get the login error if there is one
  18.         $error $authenticationUtils->getLastAuthenticationError();
  19.         // last username entered by the user
  20.         $lastUsername $authenticationUtils->getLastUsername();
  21.         return $this->render('security/login.html.twig', ['last_username' => $lastUsername'error' => $error]);
  22.     }
  23.     public function logout(): void {
  24.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  25.     }
  26.     public function requestLoginLink(LoginLinkHandlerInterface $loginLinkHandlerUserPasswordHasherInterface $userPasswordHasherRequest $request) {
  27.         // obtener el parametro del cookie para luego consultarlo al API foreneo
  28.         $userstudent $request->get('username');
  29.         $util = new Utilities();
  30.         $url $this->getParameter('api_getusersession_url');
  31.         
  32.         $username $this->getParameter('api_query_user');
  33.         $password $this->getParameter('api_query_pass');
  34.         $data = ["token" => $userstudent];
  35.         $apiresponse $util->curlResultTest($url$datafalse$username$password);
  36.         $response json_decode($apiresponse['data'], true);
  37.         if(!isset($response['id']) || empty($response['id'])) {
  38.             return $this->redirect('https://praxisonline.co');
  39.         }
  40.         $em $this->getDoctrine()->getManager();
  41.         $student $response;
  42.         // load the user in some way (e.g. using the form input)
  43.         $util->setEm($em);
  44.         $util->setUserPasswordHasher($userPasswordHasher);
  45.         $user $util->praxisNewUser($student['id'], $student['id'], 'student'true);
  46.         /*
  47.          * crear el estudiante
  48.          */
  49.         $params = [
  50.             'stdCourse' => 1,
  51.             'stdcourseLevel' => isset($student['level']) && !empty($student['level']) ? $student['level'] : 0,
  52.             'stdname' => $student['name'],
  53.             'stdlastname' => $student['last_name'],
  54.             'stdIdentification' => preg_replace('/[^\da-z]/i'''$student['id']),
  55.             'stdCampus' => $student['headquarter'],
  56.             'stdEmail' => $student['mail'],
  57.         ];
  58.         $util->createStudent($params$user);
  59.         // create a login link for $user this returns an instance
  60.         // of LoginLinkDetails
  61.         $loginLinkDetails $loginLinkHandler->createLoginLink($user);
  62.         $loginLink $loginLinkDetails->getUrl();
  63.         return $this->redirect($loginLink);
  64.     }
  65. }