src/Controller/LoginController.php line 28

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Services\TenantManager;
  4. use App\Services\SwitchTenantManager;
  5. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Component\Routing\Annotation\Route;
  8. use Symfony\Component\HttpFoundation\RedirectResponse;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class LoginController extends AbstractController
  11. {
  12.     private $tenantManager;
  13.     public function __construct(SwitchTenantManager $switchTenantManagerTenantManager $tenantManager)
  14.     {
  15.         // This is only for testing, you should try to connect to tenant in the login process
  16.         $switchTenantManager->reconnect();
  17.         $this->tenantManager $tenantManager;
  18.     }
  19.     /**
  20.      * @Route("/login", name="login")
  21.      */
  22.     public function index(AuthenticationUtils $authenticationUtils): Response
  23.     {
  24.         // get the login error if there is one
  25.         $error $authenticationUtils->getLastAuthenticationError();
  26.         // last username entered by the user
  27.         $lastUsername $authenticationUtils->getLastUsername();
  28.         return $this->render('security/login.html.twig', [
  29.                 'last_username' => $lastUsername,
  30.                 'error' => $error,
  31.                 'tenant' => $this->tenantManager->getCurrentTenant()
  32.           ]);
  33.     }
  34.     /**
  35.      * @Route("/logout", name="logout", methods={"GET"})
  36.      */
  37.     public function logout(): Response
  38.     {
  39.         $this->get('security.token_storage')->setToken(null);
  40.         $this->get('session')->invalidate();
  41.         /** redirection **/
  42.         return new RedirectResponse($this->generateUrl("login"));
  43.     }
  44.     /**
  45.      * @Route("/forget-password", name="forget_passwod")
  46.      */
  47.     public function forgetPwd(): Response
  48.     {
  49.         return $this->render('security/forget_password.html.twig', [
  50.             'tenant' => $this->tenantManager->getCurrentTenant()
  51.         ]);
  52.     }
  53. }