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(AuthenticationUtils $authenticationUtils): Response
  18.     {
  19.         // if ($this->getUser()) {
  20.         //     return $this->redirectToRoute('target_path');
  21.         // }
  22.         // get the login error if there is one
  23.         $error $authenticationUtils->getLastAuthenticationError();
  24.         // last username entered by the user
  25.         $lastUsername $authenticationUtils->getLastUsername();
  26.         return $this->render('security/login.html.twig', [
  27.             'last_username' => $lastUsername,
  28.             'error' => $error,
  29.             'seo' => [
  30.                 'title' => 'Авторизация'
  31.             ],
  32.         ]);
  33.     }
  34.     #[Route('/registration/{registrationHash}'name'registration')]
  35.     public function registration(User $userRequest $requestUserPasswordHasherInterface $encoderContractorUpdateService $contractorUpdateService): Response
  36.     {
  37. //        if ($user->getPassword() == '') {
  38. //        }
  39.         $form $this->createForm(ChangePasswordType::class, $user);
  40.         $form->handleRequest($request);
  41.         if ($form->isSubmitted() && $form->isValid()) {
  42.             $password $encoder->hashPassword($user$form->get('password')->getData());
  43.             $user->setPassword($password);
  44.             $user->setStatus(User::STATUS_ACTIVE);
  45.             $user->setRegistrationHash(null);
  46.             $this->getDoctrine()->getManager()->flush();
  47.             $contractorUpdateService->updateAfterUserRegistration($user);
  48.             return $this->redirectToRoute('app_login');
  49.         }
  50.         return $this->render('security/registration.html.twig', ['form' => $form->createView()]);
  51.     }
  52.     /**
  53.      * @Route("/logout", name="app_logout")
  54.      */
  55.     public function logout()
  56.     {
  57.         throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
  58.     }
  59. }