Skip to content

Commit a42eb79

Browse files
committed
Registration handler: Return user object
1 parent cb279fb commit a42eb79

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

src/Controller/RegistrationController.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -86,12 +86,10 @@ public function register(Request $request, string $voucher = ''): Response
8686
$form->handleRequest($request);
8787

8888
if ($form->isSubmitted() && $form->isValid()) {
89-
$this->registrationHandler->handle($registration);
89+
$user = $this->registrationHandler->handle($registration);
9090

91-
if (null !== $user = $this->manager->getRepository(User::class)->findByEmail($registration->getEmail())) {
92-
$token = new UsernamePasswordToken($user, 'default', $user->getRoles());
93-
$this->tokenStorage->setToken($token);
94-
}
91+
$token = new UsernamePasswordToken($user, 'default', $user->getRoles());
92+
$this->tokenStorage->setToken($token);
9593

9694
$recoveryToken = $user->getPlainRecoveryToken();
9795

src/Handler/RegistrationHandler.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,22 @@ class RegistrationHandler
2020
/**
2121
* Constructor.
2222
*/
23-
public function __construct(private readonly EntityManagerInterface $manager, private readonly DomainGuesser $domainGuesser, private readonly EventDispatcherInterface $eventDispatcher, private readonly PasswordUpdater $passwordUpdater, private readonly MailCryptKeyHandler $mailCryptKeyHandler, private readonly RecoveryTokenHandler $recoveryTokenHandler, private readonly bool $registrationOpen, private readonly bool $mailCrypt)
24-
{
23+
public function __construct(
24+
private readonly EntityManagerInterface $manager,
25+
private readonly DomainGuesser $domainGuesser,
26+
private readonly EventDispatcherInterface $eventDispatcher,
27+
private readonly PasswordUpdater $passwordUpdater,
28+
private readonly MailCryptKeyHandler $mailCryptKeyHandler,
29+
private readonly RecoveryTokenHandler $recoveryTokenHandler,
30+
private readonly bool $registrationOpen,
31+
private readonly bool $mailCrypt
32+
) {
2533
}
2634

2735
/**
2836
* @throws Exception
2937
*/
30-
public function handle(Registration $registration): void
38+
public function handle(Registration $registration): User
3139
{
3240
if (!$this->isRegistrationOpen()) {
3341
throw new Exception('The Registration is closed!');
@@ -53,6 +61,8 @@ public function handle(Registration $registration): void
5361
$this->manager->flush();
5462

5563
$this->eventDispatcher->dispatch(new UserEvent($user), Events::MAIL_ACCOUNT_CREATED);
64+
65+
return $user;
5666
}
5767

5868
public function isRegistrationOpen(): bool

0 commit comments

Comments
 (0)