src/Controller/SecurityController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\Pin;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\EventDispatcher\EventDispatcher;
  6. use Symfony\Component\HttpFoundation\JsonResponse;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
  10. use Symfony\Component\Security\Http\Event\InteractiveLoginEvent;
  11. class SecurityController extends AbstractController {
  12.     /**
  13.      * @Route("/login", name="login", methods={"POST", "GET"})
  14.      */
  15.     public function loginAction(Request $request) {
  16.         if($request->request->get('pin')) {
  17.             $postedPin $request->request->get('pin');
  18.             if($postedPin == "S3L7MX") {
  19.                 return $this->autologin('V4VU979jXj');
  20.             } else {
  21.                 $this->addFlash("error""Pin not valid!");
  22.             }
  23.         }
  24.         return $this->render('security/login.html.twig', [
  25.             'dcLoginId' => $_ENV['DOCCHECK_CLIENT_ID']
  26.         ]);
  27.     }
  28.     /**
  29.      * @Route("/autologin/{auth}", name="autologin")
  30.      */
  31.     public function autologin($auth) {
  32. //        // Turn off autologin
  33. //        if (!isset($_GET['dc']) || $_GET['dc'] != '1') {
  34. //            return $this->redirect($this->generateUrl('homepage'));
  35. //        }
  36. //        // end
  37.         $this->get('session')->remove('dcLogin');
  38.         if ($auth == "V4VU979jXj") {
  39.             if (isset($_GET['dc']) && $_GET['dc'] == '1') {
  40.                 $this->get('session')->set('dcLogin'true);
  41.             }
  42.             $token = new UsernamePasswordToken("user"'$2a$12$qR7kTv6J8YvfsTDXl4drJeMO0GHkJaoxwk3VHZMKipZ3vWYgDxnfO'"main", array('ROLE_USER'));
  43.             $this->get("security.token_storage")->setToken($token); //now the user is logged in
  44.             //now dispatch the login event
  45.             $request $this->get('request_stack')->getCurrentRequest();
  46.             $event = new InteractiveLoginEvent($request$token);
  47.             $dispatcher = new EventDispatcher();
  48.             $dispatcher->dispatch($event);
  49.             if ($request->getSession()->get('_security.main.target_path' ) ) {
  50.                 $url $request->getSession()->get'_security.main.target_path' );
  51.             } else {
  52.                 $url $this->generateUrl('fachbereich_home');
  53.             }
  54.             return $this->redirect($url);
  55.         }
  56.         return $this->redirect($this->generateUrl('homepage'));
  57.     }
  58.     /**
  59.      * @Route("/logout", name="app_logout", methods={"GET"})
  60.      */
  61.     public function logout(): void
  62.     {
  63.         // controller can be blank: it will never be called!
  64.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  65.     }
  66. }