src/Controller/Web/SecurityController.php line 32

Open in your IDE?
  1. <?php
  2. // src/Controller/SecurityController.php
  3. namespace App\Controller\Web;
  4. use App\Entity\User;
  5. use Psr\Log\LoggerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Session\SessionInterface;
  9. use Symfony\Component\Routing\Annotation\Route;
  10. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  11. use Symfony\Component\Security\Core\Security;
  12. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  13. class SecurityController extends AbstractController
  14. {
  15.     protected $logger;
  16.     private $session;
  17.     public function __construct(LoggerInterface $loggerSessionInterface $session)
  18.     {
  19.         $this->logger $logger;
  20.         $this->session $session;
  21.         $this->logger->debug('AcoDebug: AUTH: SecurityController::__construct');
  22.     }
  23.     /**
  24.      * @Route("/login", name="login")
  25.      */
  26.     public function login(Request $requestAuthenticationUtils $authUtilsUserPasswordEncoderInterface $encoder)
  27.     {
  28.         $this->logger->debug('AcoDebug: AUTH: SecurityController::login');
  29.         // get the login error if there is one
  30.         $error $authUtils->getLastAuthenticationError();
  31.         $errorMsg false;
  32.         if ($error) {
  33.             $errorMsg $error->getMessage();
  34.         }
  35.         // last username entered by the user
  36.         $lastUsername $authUtils->getLastUsername();
  37.         return $this->render('security/login.html.twig', [
  38.             'last_username' => $lastUsername,
  39.             'error' => $errorMsg,
  40.         ]);
  41.     }
  42.     /**
  43.      * @Route("/install/loginqr/{tgaHash}/{type}", name="installloginqr")
  44.      *
  45.      * @param mixed $tgaHash
  46.      * @param mixed $type
  47.      */
  48.     public function installLoginQr($tgaHash false$type falseRequest $request)
  49.     {
  50.         $this->logger->debug('AcoDebug: AUTH: SecurityController::installLoginQr');
  51.         // last username entered by the user
  52.         $lastAppCode '';
  53.         $errorMsg false;
  54.         // Fehler lesen UND aus der Session entfernen, damit er nicht bei jedem
  55.         // Seitenaufruf erneut erscheint (wichtig bei invalidate_session: false)
  56.         $error $this->session->get(Security::AUTHENTICATION_ERROR);
  57.         $this->session->remove(Security::AUTHENTICATION_ERROR);
  58.         // tgaHash-Priorität: Route-Parameter > GET-Parameter > Session
  59.         // (Route-Parameter ist nach Logout in der URL, Session ist nach invalidate_session leer)
  60.         if ($tgaHash && false !== $tgaHash) {
  61.             $this->session->set('tgaHash'$tgaHash);
  62.         } elseif (isset($_GET['tgaHash'])) {
  63.             $this->session->set('tgaHash'$_GET['tgaHash']);
  64.             $tgaHash $_GET['tgaHash'];
  65.         } else {
  66.             $tgaHash $this->session->get('tgaHash''');
  67.         }
  68.         if (isset($_GET['type'])) {
  69.             $this->session->set('type'$_GET['type']);
  70.         }
  71.         if ($error) {
  72.             $errorMsg $error->getMessage();
  73.         }
  74.         return $this->render('security/loginqr.html.twig', [
  75.             'last_appCode' => $lastAppCode,
  76.             'error' => $errorMsg,
  77.             'tgaHash' => $this->session->get('tgaHash'),
  78.             'type' => $this->session->get('type'),
  79.         ]);
  80.     }
  81.     /**
  82.      * @Route("/logout", name="logout", methods={"GET"})
  83.      */
  84.     public function logout()
  85.     {
  86.         // controller can be blank: it will never be executed!
  87.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  88.     }
  89.     /**
  90.      * @Route("/install/logoutqr/{tgaHash}", name="logoutqr", methods={"GET"})
  91.      *
  92.      * @param mixed $tgaHash
  93.      */
  94.     public function logoutQr($tgaHash)
  95.     {
  96.         // controller can be blank: it will never be executed!
  97.         throw new \Exception('Don\'t forget to activate logout in security.yaml');
  98.     }
  99. }