src/Controller/SecurityController.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\User;
  4. use App\Form\ChangePasswordType;
  5. use App\Service\ContractorUpdateService;
  6. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  7. use Symfony\Component\HttpFoundation\Request;
  8. use Symfony\Component\HttpFoundation\Response;
  9. use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
  10. use Symfony\Component\Routing\Annotation\Route;
  11. use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
  12. class SecurityController extends AbstractController
  13. {
  14.     /**
  15.      * @Route("/login", name="app_login", methods={"POST", "GET"})
  16.      */
  17.     public function login(Request $requestAuthenticationUtils $authenticationUtils): Response
  18.     {
  19.         $credentials = [
  20.             'email' => $request->getSession()->get('login_reserve_failure_email'),
  21.             'password' => $request->getSession()->get('login_reserve_failure_password'),
  22.         ];
  23.         // if ($this->getUser()) {
  24.         //     return $this->redirectToRoute('target_path');
  25.         // }
  26.         // get the login error if there is one
  27.         $error $authenticationUtils->getLastAuthenticationError();
  28.         // last username entered by the user
  29.         $lastUsername $authenticationUtils->getLastUsername();
  30.         return $this->render('security/login.html.twig', [
  31.             'last_username' => $lastUsername,
  32.             'credentials' => $credentials,
  33.             'error' => $error,
  34.             'seo' => [
  35.                 'title' => 'Авторизация'
  36.             ],
  37.         ]);
  38.     }
  39.     /**
  40.      * @Route("/login-reserve", name="app_login_reserve", methods={"POST", "GET"})
  41.      */
  42.     public function loginReserve(Request $requestAuthenticationUtils $authenticationUtils): Response
  43.     {
  44.         $credentials = [
  45.             'email' => $request->getSession()->get('login_failure_email'),
  46.             'password' => $request->getSession()->get('login_failure_password'),
  47.         ];
  48.         // get the login error if there is one
  49.         $error $authenticationUtils->getLastAuthenticationError();
  50.         // last username entered by the user
  51.         $lastUsername $authenticationUtils->getLastUsername();
  52.         return $this->render('security/login-reserve.html.twig', [
  53.             'last_username' => $lastUsername,
  54.             'credentials' => $credentials,
  55.             'error' => $error,
  56.             'seo' => [
  57.                 'title' => 'Авторизация'
  58.             ],
  59.         ]);
  60.     }
  61.     #[Route('/registration/{registrationHash}'name'registration')]
  62.     public function registration(User $userRequest $requestUserPasswordHasherInterface $encoderContractorUpdateService $contractorUpdateService): Response
  63.     {
  64. //        if ($user->getPassword() == '') {
  65. //        }
  66.         $form $this->createForm(ChangePasswordType::class, $user);
  67.         $form->handleRequest($request);
  68.         if ($form->isSubmitted() && $form->isValid()) {
  69.             $password $encoder->hashPassword($user$form->get('password')->getData());
  70.             $user->setPassword($password);
  71.             $user->setStatus(User::STATUS_ACTIVE);
  72.             $user->setRegistrationHash(null);
  73.             $this->getDoctrine()->getManager()->flush();
  74.             $contractorUpdateService->updateAfterUserRegistration($user);
  75.             return $this->redirectToRoute('app_login');
  76.         }
  77.         return $this->render('security/registration.html.twig', ['form' => $form->createView()]);
  78.     }
  79.     /**
  80.      * @Route("/logout", name="app_logout")
  81.      */
  82.     public function logout()
  83.     {
  84.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  85.     }
  86. }