Expand user and allow everybody to register

Automatically login after registering
This commit is contained in:
Tim
2023-04-03 22:19:28 +02:00
parent 5be77eeba1
commit bf83e5aabd
8 changed files with 161 additions and 3 deletions

View File

@ -7,6 +7,7 @@ use App\Form\RegistrationFormType;
use Doctrine\ORM\EntityManagerInterface;
use Exception;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Bundle\SecurityBundle\Security;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\PasswordHasher\Hasher\UserPasswordHasherInterface;
@ -39,6 +40,7 @@ class SecurityController extends AbstractController
Request $request,
UserPasswordHasherInterface $userPasswordHasher,
EntityManagerInterface $entityManager,
Security $security,
): Response
{
$user = new User();
@ -59,9 +61,11 @@ class SecurityController extends AbstractController
$entityManager->persist($user);
$entityManager->flush();
// do anything else you need here, like send an email
$this->addFlash('success', sprintf('Successfully registered user %s', $user->getUsername()));
$this->addFlash('success', sprintf('Successfully registered user %s and logged in', $user->getUsername()));
return $this->redirectToRoute('register');
$security->login($user, 'remember_me');
return $this->redirectToRoute('user_profile');
}
}