Expand user and allow everybody to register
Automatically login after registering
This commit is contained in:
@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user