src/Controller/SecurityController.php line 18

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Symfony\Component\HttpFoundation\Request;
  5. use Symfony\Component\Routing\Annotation\Route;
  6. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  7. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  8. use Symfony\Component\EventDispatcher\EventDispatcher;
  9. class SecurityController extends AbstractController {
  10.     /**
  11.      * @Route("/login", name="login", methods={"POST", "GET"})
  12.      */
  13.     public function loginAction(Request $request) {
  14.         if($request->request->get('pin')) {
  15.             $postedPin $request->request->get('pin');
  16.             if($postedPin == "S3L7MX") {
  17.                 return $this->autologin('V4VU979jXj');
  18.             } else {
  19.                 $this->addFlash("error""Pin not valid!");
  20.             }
  21.         }
  22.         return $this->render('/security/login.html.twig', [
  23.             'dcLoginId' => $_ENV['DOCCHECK_CLIENT_ID']
  24.         ]);
  25.     }
  26.     /**
  27.      * @Route("/autologin/{auth}", name="autologin")
  28.      */
  29.     public function autologin($auth) {
  30.         if ($auth == "V4VU979jXj") {
  31.             if (isset($_GET['dc']) && $_GET['dc'] == '1') {
  32.                 $this->get('session')->set('dcLogin'true);
  33.             }
  34.             $token = new UsernamePasswordToken("user"'$2a$12$qR7kTv6J8YvfsTDXl4drJeMO0GHkJaoxwk3VHZMKipZ3vWYgDxnfO'"main", array('ROLE_USER'));
  35.             $this->get("security.token_storage")->setToken($token); //now the user is logged in
  36.             //now dispatch the login event
  37.             $request $this->get('request_stack')->getCurrentRequest();
  38.             $event = new InteractiveLoginEvent($request$token);
  39.             $dispatcher = new EventDispatcher();
  40.             $dispatcher->dispatch($event);
  41.             if ( $request->getSession()->get('_security.main.target_path' ) ) {
  42.                 $url $request->getSession()->get'_security.main.target_path' );
  43.             } else {
  44.                 $url $this->generateUrl('homepage');
  45.             }
  46.             return $this->redirect($url);
  47.         }
  48.         return $this->redirect($this->generateUrl('login'));
  49.     }
  50. }