src/Controller/Admin/AuthController.php line 33

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Admin;
  3. use App\Enum\ContainerType;
  4. use App\Form\Admin\PasswordReminderChangeType;
  5. use App\Form\Admin\PasswordReminderType;
  6. use App\Repository\SitesRepository;
  7. use App\Service\PasswordReminderService;
  8. use Random\RandomException;
  9. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  10. use Symfony\Component\HttpFoundation\Request;
  11. use Symfony\Component\HttpFoundation\Response;
  12. use Symfony\Component\Routing\Annotation\Route;
  13. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  14. use Twig\Error\LoaderError;
  15. use Twig\Error\RuntimeError;
  16. use Twig\Error\SyntaxError;
  17. /**
  18.  * Class AuthController
  19.  * @package App\Controller\Admin
  20.  */
  21. class AuthController extends AbstractController
  22. {
  23.     /**
  24.      * @Route("/admin/login", name="admin_login")
  25.      *
  26.      * @param AuthenticationUtils $authenticationUtils
  27.      * @param SitesRepository $sitesRepository
  28.      * @return Response
  29.      */
  30.     public function login(AuthenticationUtils $authenticationUtilsSitesRepository $sitesRepository): Response
  31.     {
  32.         $error $authenticationUtils->getLastAuthenticationError();
  33.         $username $authenticationUtils->getLastUsername();
  34.         if (
  35.             $this->getUser() &&
  36.             $this->getUser()->getType() &&
  37.             (in_array($this->getUser()->getType(), ['ADMIN''OPERATION''CUSTOMER_REPRESENTATIVE''ACCOUNTING_DEPARTMENT']))
  38.         ) {
  39.             return $this->redirectToRoute('admin_home');
  40.         }
  41.         return $this->render('admin/auth/login.html.twig', [
  42.             'lastUsername' => $username,
  43.             'error' => $error,
  44.             'sites' => $sitesRepository->findAll(),
  45.         ]);
  46.     }
  47.     /**
  48.      * @Route("/admin/logout", name="admin_logout")
  49.      * @param AuthenticationUtils $authenticationUtils
  50.      * @return Response
  51.      */
  52.     public function logout(AuthenticationUtils $authenticationUtils): Response
  53.     {
  54.     }
  55.     /**
  56.      * @Route("/admin/password_reminder", name="admin_password_reminder")
  57.      *
  58.      * @param Request $request
  59.      * @param PasswordReminderService $passwordReminder
  60.      * @param SitesRepository $sitesRepository
  61.      * @return Response
  62.      * @throws RandomException
  63.      * @throws LoaderError
  64.      * @throws RuntimeError
  65.      * @throws SyntaxError
  66.      */
  67.     public function passwordReminder(Request $requestPasswordReminderService $passwordReminderSitesRepository $sitesRepository): Response
  68.     {
  69.         $status false;
  70.         $form $this->createForm(PasswordReminderType::class);
  71.         $form->handleRequest($request);
  72.         if ($form->isSubmitted() && $form->isValid()) {
  73.             $email $form->get("email")->getData();
  74.             $status $passwordReminder->handle($emailContainerType::ADMIN);
  75.         }
  76.         return $this->render('admin/auth/password_reminder.html.twig', [
  77.             "form" => $form->createView(),
  78.             "status" => $status,
  79.             'sites' => $sitesRepository->findAll(),
  80.         ]);
  81.     }
  82.     /**
  83.      * @Route("/admin/password_approval/{token}", name="admin_password_approval")
  84.      *
  85.      * @param Request $request
  86.      * @param PasswordReminderService $passwordReminder
  87.      * @param $token
  88.      * @param SitesRepository $sitesRepository
  89.      * @return Response
  90.      */
  91.     public function passwordApproval(Request $requestPasswordReminderService $passwordReminder$tokenSitesRepository $sitesRepository): Response
  92.     {
  93.         if ($passwordReminder->hasToken($token)) {
  94.             $status false;
  95.             $form $this->createForm(PasswordReminderChangeType::class);
  96.             $form->handleRequest($request);
  97.             if ($form->isSubmitted() && $form->isValid()) {
  98.                 $password $form->get("password")->getData();
  99.                 $status $passwordReminder->approvalPasswordChange($token$password$this->getDoctrine());
  100.             }
  101.             return $this->render('admin/auth/password_approval.html.twig', [
  102.                 "form" => $form->createView(),
  103.                 "status" => $status,
  104.                 'sites' => $sitesRepository->findAll(),
  105.             ]);
  106.         } else {
  107.             return new Response("");
  108.         }
  109.     }
  110. }