<?php
namespace App\Controller;
use App\Entity\User;
use App\Form\ChangePasswordType;
use App\Service\ContractorUpdateService;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
class SecurityController extends AbstractController
{
/**
* @Route("/login", name="app_login", methods={"POST", "GET"})
*/
public function login(AuthenticationUtils $authenticationUtils): Response
{
// if ($this->getUser()) {
// return $this->redirectToRoute('target_path');
// }
// get the login error if there is one
$error = $authenticationUtils->getLastAuthenticationError();
// last username entered by the user
$lastUsername = $authenticationUtils->getLastUsername();
return $this->render('security/login.html.twig', [
'last_username' => $lastUsername,
'error' => $error,
'seo' => [
'title' => 'Авторизация'
],
]);
}
#[Route('/registration/{registrationHash}', name: 'registration')]
public function registration(User $user, Request $request, UserPasswordHasherInterface $encoder, ContractorUpdateService $contractorUpdateService): Response
{
// if ($user->getPassword() == '') {
// }
$form = $this->createForm(ChangePasswordType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$password = $encoder->hashPassword($user, $form->get('password')->getData());
$user->setPassword($password);
$user->setStatus(User::STATUS_ACTIVE);
$user->setRegistrationHash(null);
$this->getDoctrine()->getManager()->flush();
$contractorUpdateService->updateAfterUserRegistration($user);
return $this->redirectToRoute('app_login');
}
return $this->render('security/registration.html.twig', ['form' => $form->createView()]);
}
/**
* @Route("/logout", name="app_logout")
*/
public function logout()
{
throw new \LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
}
}