src/Controller/LoginController.php line 39

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Lib\Misc\ConfManager;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\HttpFoundation\Session\Session;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use App\Lib\Auth\CASAuthentication;
  11. use App\Lib\Auth\CookieManager;
  12. use App\Lib\Services\ThreeDSPlatform;
  13. class LoginController extends AbstractController
  14. {
  15.     private $session;
  16.     private $conf;
  17.     private $authCtrl;
  18.     /**
  19.      * LoginController constructor.
  20.      * @param SessionInterface $session
  21.      */
  22.     public function __construct(SessionInterface $sessionConfManager $conf)
  23.     {
  24.         $this->session $session;
  25.         $this->conf $conf;
  26.     }
  27.     /**
  28.      * @Route("/login", name="login")
  29.      * @param Request $request
  30.      * @return Response
  31.      * @throws \Exception
  32.      */
  33.     public function index(Request $request)
  34.     {
  35.         $user '';
  36.         $error '';
  37.         $post $request->request->all();
  38.         $auth = array();
  39.         if(isset($post["user"]) && isset($post["password"])) {
  40.             /***************************
  41.              * For the login, we provide a fake session ID to ensure a cookie can be created.
  42.              * When the client receive a DS session, we delete the fake session
  43.              */
  44.             $tmpObj = new \stdClass();
  45.             $tmpObj->id uniqid();
  46.             $this->session->set("me"$tmpObj);
  47.             $clonedSessionId $tmpObj->id;
  48.             unset($tmpObj);
  49.             CookieManager::createCookieDirFromId($clonedSessionId);
  50.             $this->session->set("credentials",
  51.                 array(
  52.                     "user" => $post["user"],
  53.                     "password" => $post["password"]
  54.                 )
  55.                 );
  56.             $tenant $this->getParameter("tenant");
  57.             $meUrl "https://eu1-ifwe.3dexperience.3ds.com/api/users/current";
  58.             $casAuthentication = new CASAuthentication($this->session$this->conf);
  59.             $auth $casAuthentication->doAuthFor($tenant,$meUrl);
  60.             if(!empty($auth)) {
  61.                 $threeDSPlatform = new ThreeDSPlatform($casAuthentication$this->session$this->conf);
  62.                 $me $threeDSPlatform->getMeInfos();
  63.                 $this->session->set("me"$me);
  64.                 //renaming fake session
  65.                 CookieManager::renameCookieDir($clonedSessionId$this->session);
  66.                 return $this->redirectToRoute('main');
  67.             }
  68.         }
  69.         //CookieManager::resetCookie($clonedSession);
  70.         return $this->render('login/index.html.twig', [
  71.             'user' => $user,
  72.             'error' => $error,
  73.         ]);
  74.     }
  75. }