src/Controller/SecurityController.php line 82

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  4. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  5. use Symfony\Component\HttpFoundation\RedirectResponse;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Symfony\Component\HttpFoundation\Response;
  8. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  9. use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
  10. use App\Entity\User;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use App\Manager\UserManager;
  13. class SecurityController extends AbstractController
  14. {
  15.     /**
  16.      * @var UserPasswordEncoderInterface
  17.      */
  18.     private $passwordEncoder;
  19.     public function __construct(UserPasswordEncoderInterface $passwordEncoder)
  20.     {
  21.         $this->passwordEncoder $passwordEncoder;
  22.     }
  23.     /**
  24.      * @Route("/login", name="app_login")
  25.      */
  26.     public function login(AuthenticationUtils $authenticationUtils): Response
  27.     {
  28.         $error $authenticationUtils->getLastAuthenticationError();
  29.         $lastUsername $authenticationUtils->getLastUsername();
  30.         return $this->render('security/login.html.twig', [
  31.             'last_username' => $lastUsername,
  32.             'error' => $error,
  33.         ]);
  34.     }
  35.     /**
  36.      * @Route("/logout", name="app_logout")
  37.      */
  38.     public function logout()
  39.     {
  40.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  41.     }
  42.     /**
  43.      * @Route("/reset-password/{token}", name="app_reset_password_mail")
  44.      */
  45.     public function getResetPassword(Request $requeststring $tokenUserManager $userManager): Response
  46.     {
  47.         $inputVariables $userManager->getInputErrors(['inputErrors']);
  48.         return $this->render('security/reset-password.html.twig', [
  49.             'token' => $token,
  50.             'inputErrors' => $inputVariables['inputErrors'],
  51.         ]);
  52.     }
  53.     /**
  54.      * @Route("/register", name="app_register")
  55.      */
  56.     public function register(Request $requestUserPasswordEncoderInterface $userPasswordEncoderEntityManagerInterface $entityManagerUserManager $userManager): Response
  57.     {
  58.         $stripeVariables $userManager->getStripeErrors(['stripeErrors']);
  59.         $inputVariables $userManager->getInputErrors(['inputErrors']);
  60.         $variables $userManager->getSectorsVariables(['sectors']);
  61.         return $this->render('registration/register.html.twig', [
  62.             'stripeErrors' => $stripeVariables['stripeErrors'],
  63.             'sectors' => $variables['sectors'],
  64.             'inputErrors' => $inputVariables['inputErrors'],
  65.         ]);
  66.     }
  67.     /**
  68.      * @Route("/forgot-password", name="app_forgot_password")
  69.      */
  70.     public function forgotPassword(UserManager $userManager): Response
  71.     {
  72.         $inputVariables $userManager->getInputErrors(['inputErrors']);
  73.         return $this->render('forgot-password/forgot-password.html.twig', [
  74.             'controller_name' => 'ForgotPasswordController',
  75.             'inputErrors' => $inputVariables['inputErrors'],
  76.         ]);
  77.     }
  78.     /**
  79.      * @Route("/tmpLogin/{token}", name="app_tmp_login")
  80.      */
  81.     public function tmpLogin(Request $requeststring $token)
  82.     {
  83.         $em $this->getDoctrine()->getManager();
  84.         $user $em->getRepository(User::class)->findOneBy([
  85.             'confirmationToken' => $token,
  86.         ]);
  87.         if (is_null($user)) {
  88.             return new RedirectResponse($this->container->get('router')->generate('app_login'));
  89.         } else {
  90.             return new RedirectResponse($this->container->get('router')->generate('app_show_dashboard'));
  91.         }
  92.     }
  93. }