Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/Command/User/CreateCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@ public function __construct(
parent::__construct();
}

/**
* @param array<string> $roles
*/
public function __invoke(
SymfonyStyle $io,
#[Argument(description: 'The email of the user')] string $email,
#[Argument(description: 'The locale to use')] string $locale = 'nl',
#[Argument(description: 'The roles of the user')] array $roles = ['ROLE_USER'],
): int {
$message = new CreateUser();
$message->email = $email;
$message->locale = $locale;
$message->roles = $roles;

$constraints = $this->validator->validate($message);
Expand Down
5 changes: 4 additions & 1 deletion src/Controller/User/Admin/AddUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ public function __invoke(Request $request): Response
$form->handleRequest($request);

if ($form->isSubmitted() && $form->isValid()) {
$this->messageBus->dispatch($form->getData());
/** @var CreateUser $message */
$message = $form->getData();
$message->locale = $request->getLocale();
$this->messageBus->dispatch($message);

$this->addFlash(
'success',
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/User/Admin/RequestConfirmationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Entity\User\User;
use App\Message\User\SendConfirmation;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Attribute\Route;
Expand All @@ -19,7 +20,7 @@ public function __construct(
) {
}

public function __invoke(User $user): Response
public function __invoke(User $user, Request $request): Response
{
if ($user->isConfirmed()) {
$this->addFlash(
Expand All @@ -30,7 +31,7 @@ public function __invoke(User $user): Response
return $this->redirectToRoute('user_admin_edit', ['user' => $user->getId()]);
}

$this->messageBus->dispatch(new SendConfirmation($user));
$this->messageBus->dispatch(new SendConfirmation($user, $request->getLocale()));

$this->addFlash(
'success',
Expand Down
5 changes: 3 additions & 2 deletions src/Controller/User/ResendConfirmationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use App\Message\User\SendConfirmation;
use App\Repository\User\UserRepository;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Messenger\MessageBusInterface;
use Symfony\Component\Routing\Attribute\Route;
Expand All @@ -21,7 +22,7 @@ public function __construct(
) {
}

public function __invoke(string $token): Response
public function __invoke(string $token, Request $request): Response
{
$user = $this->userRepository->findOneBy(['confirmationToken' => $token]);

Expand All @@ -34,7 +35,7 @@ public function __invoke(string $token): Response
return $this->redirectToRoute('login');
}

$this->messageBus->dispatch(new SendConfirmation($user));
$this->messageBus->dispatch(new SendConfirmation($user, $request->getLocale()));

$this->addFlash('success', $this->translator->trans('Confirmation mail successfully resent'));

Expand Down
2 changes: 2 additions & 0 deletions src/DataTransferObject/User/UserDataTransferObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ class UserDataTransferObject
* @var array<int, string> $roles
*/
public array $roles = [];

public string $locale;
}
3 changes: 2 additions & 1 deletion src/Message/User/SendConfirmation.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
class SendConfirmation
{
public function __construct(
public readonly User $user
public readonly User $user,
public readonly string $locale
) {
}
}
2 changes: 1 addition & 1 deletion src/MessageHandler/User/CreateUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function __invoke(CreateUser $message): User
);
$user->requestPassword();
$this->userRepository->add($user);
$this->messageBus->dispatch(new SendConfirmation($user));
$this->messageBus->dispatch(new SendConfirmation($user, $message->locale));

return $user;
}
Expand Down
2 changes: 1 addition & 1 deletion src/MessageHandler/User/RegisterUserHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function __invoke(RegisterUser $message): void
$encodedPassword = $this->passwordEncoder->hashPassword($user, $message->password);
$user->setPassword($encodedPassword);
$this->userRepository->add($user);
$this->messageBus->dispatch(new SendConfirmation($user));
$this->messageBus->dispatch(new SendConfirmation($user, $message->locale));
}
}
1 change: 1 addition & 0 deletions src/MessageHandler/User/SendConfirmationHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public function __invoke(SendConfirmation $message): User
'confirmationLink' => $this->router->generate(
'user_confirm',
[
'_locale' => $message->locale,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚨 suggestion (security): Passing locale in the confirmation link may expose internal details.

Validate the locale value before including it in URLs to prevent potential spoofing or exposure of sensitive information.

'token' => $user->getConfirmationToken(),
],
RouterInterface::ABSOLUTE_URL
Expand Down