<?php
namespace App\Controller;
use App\Services\TenantManager;
use App\Services\SwitchTenantManager;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class LoginController extends AbstractController
{
private $tenantManager;
public function __construct(SwitchTenantManager $switchTenantManager, TenantManager $tenantManager)
{
// This is only for testing, you should try to connect to tenant in the login process
$switchTenantManager->reconnect();
$this->tenantManager = $tenantManager;
}
/**
* @Route("/login", name="login")
*/
public function index(AuthenticationUtils $authenticationUtils): Response
{
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'tenant' => $this->tenantManager->getCurrentTenant()
]);
}
/**
* @Route("/logout", name="logout", methods={"GET"})
*/
public function logout(): Response
{
$this->get('security.token_storage')->setToken(null);
$this->get('session')->invalidate();
/** redirection **/
return new RedirectResponse($this->generateUrl("login"));
}
/**
* @Route("/forget-password", name="forget_passwod")
*/
public function forgetPwd(): Response
{
return $this->render('security/forget_password.html.twig', [
'tenant' => $this->tenantManager->getCurrentTenant()
]);
}
}