src/Controller/AuthController.php line 17

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\UserVerificationTokens;
  4. use App\Entity\Users;
  5. use Doctrine\ORM\EntityManagerInterface;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\Routing\Annotation\Route;
  9. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  10. class AuthController extends AbstractController
  11. {
  12.     #[Route('/login'name'login')]
  13.     public function login(Request $requestAuthenticationUtils $authenticationUtils)
  14.     {
  15.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  16.             return $this->redirectToRoute('users');
  17.         }
  18.         $errors $authenticationUtils->getLastAuthenticationError();
  19.         $lastUsername $authenticationUtils->getLastUsername();
  20.         return $this->render('security/login.html.twig', [
  21.             'error'         => $errors,
  22.             'last_username' => $lastUsername,
  23.         ]);
  24.     }
  25.     /**
  26.      * @Route("/login_success", name="login_success")
  27.      */
  28.     public function postLoginRedirectAction()
  29.     {
  30.         if ($this->isGranted('ROLE_PARTNER')) {
  31.             return $this->redirectToRoute('app_partners_vouchers');
  32.         }
  33.         if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
  34.             return $this->redirectToRoute('users');
  35.         }
  36.     }
  37.     /**
  38.      * @Route("/logout", name="logout")
  39.      */
  40.     public function logout()
  41.     {
  42.     }
  43.     #[Route('/email_verification/{token}'name'email_verification')]
  44.     public function emailVerificationPage($tokenRequest $requestEntityManagerInterface $em) {
  45.         $lang $request->get('lang''ro');
  46.         $user $em
  47.             ->getRepository(Users::class)
  48.             ->getByVerificationToken($token);
  49.         if (null === $user) {
  50.             return $this->render(
  51.                 "account_creation/verificationFailure"ucfirst($lang) . ".html.twig",
  52.                 ['lang' => $lang]
  53.             );
  54.         }
  55.         // verify user
  56.         $user->setEmailVerified(true);
  57.         $user->setUpdatedAt(new \DateTime());
  58.         // invalidate token
  59.         $em->getRepository(UserVerificationTokens::class)->deleteByToken($token);
  60.         $em->flush();
  61.         return $this->render(
  62.             "account_creation/verificationSuccess"ucfirst($lang) . ".html.twig",
  63.             ['lang' => $user->getLang()]
  64.         );
  65.     }
  66. //    /**
  67. //     * @Route("/fix", name="fix")
  68. //     */
  69. //    public function fixAction(UserPasswordHasherInterface $passwordHasher, EntityManagerInterface $em)
  70. //    {
  71. //        $user = new Administrators();
  72. //        $user->setEmail('andrei');
  73. //        $user->setUsername('andrei');
  74. //        $user->setFirstname('Andrei');
  75. //        $user->setLastname('Admin');
  76. //        $user->setCreated(new \DateTime());
  77. //        $user->setActive(true);
  78. //
  79. //        $encoded = $passwordHasher->hashPassword($user, '2019@Andrei');
  80. //        $user->setPassword($encoded);
  81. //
  82. //        $em->persist($user);
  83. //        $em->flush();
  84. //    }
  85. }