<?php
// src/Controller/SecurityController.php
namespace App\Controller\Web;
use App\Entity\User;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Symfony\Component\Security\Core\Security;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
protected $logger;
private $session;
public function __construct(LoggerInterface $logger, SessionInterface $session)
{
$this->logger = $logger;
$this->session = $session;
$this->logger->debug('AcoDebug: AUTH: SecurityController::__construct');
}
/**
* @Route("/login", name="login")
*/
public function login(Request $request, AuthenticationUtils $authUtils, UserPasswordEncoderInterface $encoder)
{
$this->logger->debug('AcoDebug: AUTH: SecurityController::login');
// get the login error if there is one
$error = $authUtils->getLastAuthenticationError();
$errorMsg = false;
if ($error) {
$errorMsg = $error->getMessage();
}
// last username entered by the user
$lastUsername = $authUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $errorMsg,
]);
}
/**
* @Route("/install/loginqr/{tgaHash}/{type}", name="installloginqr")
*
* @param mixed $tgaHash
* @param mixed $type
*/
public function installLoginQr($tgaHash = false, $type = false, Request $request)
{
$this->logger->debug('AcoDebug: AUTH: SecurityController::installLoginQr');
// last username entered by the user
$lastAppCode = '';
$errorMsg = false;
// Fehler lesen UND aus der Session entfernen, damit er nicht bei jedem
// Seitenaufruf erneut erscheint (wichtig bei invalidate_session: false)
$error = $this->session->get(Security::AUTHENTICATION_ERROR);
$this->session->remove(Security::AUTHENTICATION_ERROR);
// tgaHash-Priorität: Route-Parameter > GET-Parameter > Session
// (Route-Parameter ist nach Logout in der URL, Session ist nach invalidate_session leer)
if ($tgaHash && false !== $tgaHash) {
$this->session->set('tgaHash', $tgaHash);
} elseif (isset($_GET['tgaHash'])) {
$this->session->set('tgaHash', $_GET['tgaHash']);
$tgaHash = $_GET['tgaHash'];
} else {
$tgaHash = $this->session->get('tgaHash', '');
}
if (isset($_GET['type'])) {
$this->session->set('type', $_GET['type']);
}
if ($error) {
$errorMsg = $error->getMessage();
}
return $this->render('security/loginqr.html.twig', [
'last_appCode' => $lastAppCode,
'error' => $errorMsg,
'tgaHash' => $this->session->get('tgaHash'),
'type' => $this->session->get('type'),
]);
}
/**
* @Route("/logout", name="logout", methods={"GET"})
*/
public function logout()
{
// controller can be blank: it will never be executed!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
/**
* @Route("/install/logoutqr/{tgaHash}", name="logoutqr", methods={"GET"})
*
* @param mixed $tgaHash
*/
public function logoutQr($tgaHash)
{
// controller can be blank: it will never be executed!
throw new \Exception('Don\'t forget to activate logout in security.yaml');
}
}