|
|
|
@ -20,6 +20,10 @@ use Symfony\Component\Security\Http\Authentication\AuthenticationUtils;
|
|
|
|
|
use Symfony\Contracts\Translation\TranslatorInterface;
|
|
|
|
|
use SymfonyCasts\Bundle\VerifyEmail\Exception\VerifyEmailExceptionInterface;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Controllers for user pages
|
|
|
|
|
*/
|
|
|
|
|
#[Route('/user')]
|
|
|
|
|
class UserController extends AbstractController {
|
|
|
|
|
/**
|
|
|
|
|
* @var TranslatorInterface The translator service
|
|
|
|
@ -54,6 +58,10 @@ class UserController extends AbstractController {
|
|
|
|
|
*/
|
|
|
|
|
#[Route('/signUp', name: 'user_signUp')]
|
|
|
|
|
public function signUp (Request $request, UserPasswordHasherInterface $userPasswordHasher, EntityManagerInterface $entityManager): Response {
|
|
|
|
|
if (($response = $this->checkUserNotConnected())) {
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$user = new User();
|
|
|
|
|
|
|
|
|
|
$form = $this->createForm(SignUpFormType::class, $user);
|
|
|
|
@ -144,18 +152,8 @@ class UserController extends AbstractController {
|
|
|
|
|
*/
|
|
|
|
|
#[Route(path: '/signIn', name: 'user_signIn')]
|
|
|
|
|
public function login (AuthenticationUtils $authenticationUtils): Response {
|
|
|
|
|
/** @var User|null $user */
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
if ($user !== null) {
|
|
|
|
|
$this->addFlash(
|
|
|
|
|
'warning',
|
|
|
|
|
$this->translator->trans(
|
|
|
|
|
'pages.emailVerify.warningAlreadyConnected',
|
|
|
|
|
[
|
|
|
|
|
'signOutUrl' => $this->generateUrl('user_signOut'),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
if (($response = $this->checkUserNotConnected())) {
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (($error = $authenticationUtils->getLastAuthenticationError()) !== null) {
|
|
|
|
@ -180,4 +178,28 @@ class UserController extends AbstractController {
|
|
|
|
|
public function logout (): void {
|
|
|
|
|
throw new LogicException('This method can be blank - it will be intercepted by the logout key on your firewall.');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Check the user is NOT connected
|
|
|
|
|
*
|
|
|
|
|
* @return Response|null The response (warning and redirect) if user is connected, else Null
|
|
|
|
|
*/
|
|
|
|
|
private function checkUserNotConnected (): ?Response {
|
|
|
|
|
/** @var User|null $user */
|
|
|
|
|
$user = $this->getUser();
|
|
|
|
|
if ($user === null) {
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$this->addFlash(
|
|
|
|
|
'warning',
|
|
|
|
|
$this->translator->trans(
|
|
|
|
|
'pages.emailVerify.warningAlreadyConnected',
|
|
|
|
|
[
|
|
|
|
|
'signOutUrl' => $this->generateUrl('user_signOut'),
|
|
|
|
|
]
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
return $this->redirectToRoute('core_main');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|