mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
Apply suggestions from code review
This commit is contained in:
parent
fe843f4157
commit
525cadc45f
5 changed files with 10 additions and 20 deletions
|
|
@ -20,8 +20,8 @@ class SendAccountRegistrationEmail
|
|||
{
|
||||
public function __construct(
|
||||
public readonly string $shopUserEmail,
|
||||
public readonly string $localeCode,
|
||||
public readonly string $channelCode,
|
||||
public readonly string $localeCode,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ namespace Sylius\Bundle\CoreBundle\Command\Shop\Account;
|
|||
class VerifyShopUser
|
||||
{
|
||||
public function __construct(
|
||||
public readonly string $token,
|
||||
public readonly string $channelCode,
|
||||
public readonly string $localeCode,
|
||||
public readonly string $token,
|
||||
) {
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -20,9 +20,10 @@ use Sylius\Component\Core\Model\ChannelInterface;
|
|||
use Sylius\Component\Core\Model\ShopUserInterface;
|
||||
use Sylius\Component\User\Repository\UserRepositoryInterface;
|
||||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final class SendAccountRegistrationEmailHandler
|
||||
final readonly class SendAccountRegistrationEmailHandler
|
||||
{
|
||||
public function __construct(
|
||||
private UserRepositoryInterface $shopUserRepository,
|
||||
|
|
@ -35,19 +36,11 @@ final class SendAccountRegistrationEmailHandler
|
|||
{
|
||||
/** @var ShopUserInterface|null $shopUser */
|
||||
$shopUser = $this->shopUserRepository->findOneByEmail($command->shopUserEmail);
|
||||
if (null === $shopUser) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('There is no shop user with %s email', $command->shopUserEmail),
|
||||
);
|
||||
}
|
||||
Assert::notNull($shopUser, sprintf('There is no shop user with %s email', $command->shopUserEmail));
|
||||
|
||||
/** @var ChannelInterface|null $channel */
|
||||
$channel = $this->channelRepository->findOneByCode($command->channelCode);
|
||||
if (null === $channel) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('There is no channel with %s code', $command->channelCode),
|
||||
);
|
||||
}
|
||||
Assert::notNull($channel, sprintf('There is no channel with %s email', $command->channelCode));
|
||||
|
||||
if ($channel->isAccountVerificationRequired() && !$shopUser->isEnabled()) {
|
||||
return;
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ use Symfony\Component\Clock\ClockInterface;
|
|||
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
|
||||
use Symfony\Component\Messenger\MessageBusInterface;
|
||||
use Symfony\Component\Messenger\Stamp\DispatchAfterCurrentBusStamp;
|
||||
use Webmozart\Assert\Assert;
|
||||
|
||||
#[AsMessageHandler]
|
||||
final readonly class VerifyShopUserHandler
|
||||
|
|
@ -37,18 +38,14 @@ final readonly class VerifyShopUserHandler
|
|||
{
|
||||
/** @var ShopUserInterface|null $user */
|
||||
$user = $this->shopUserRepository->findOneBy(['emailVerificationToken' => $command->token]);
|
||||
if (null === $user) {
|
||||
throw new \InvalidArgumentException(
|
||||
sprintf('There is no shop user with %s email verification token', $command->token),
|
||||
);
|
||||
}
|
||||
Assert::notNull($user, sprintf('There is no shop user with %s email verification token', $command->token));
|
||||
|
||||
$user->setVerifiedAt($this->clock->now());
|
||||
$user->setEmailVerificationToken(null);
|
||||
$user->enable();
|
||||
|
||||
$this->commandBus->dispatch(
|
||||
new SendAccountRegistrationEmail($user->getEmail(), $command->localeCode, $command->channelCode),
|
||||
new SendAccountRegistrationEmail($user->getEmail(), $command->channelCode, $command->localeCode),
|
||||
[new DispatchAfterCurrentBusStamp()],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,9 +55,9 @@ final readonly class VerifyShopUserAction
|
|||
}
|
||||
|
||||
$this->messageBus->dispatch(new VerifyShopUser(
|
||||
$token,
|
||||
$this->channelContext->getChannel()->getCode(),
|
||||
$this->localeContext->getLocaleCode(),
|
||||
$token,
|
||||
));
|
||||
|
||||
FlashBagProvider::getFlashBag($this->requestStack)->add('success', 'sylius.user.verify_email');
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue