mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
refactor #13830 [API] Use the Calendar component in command handlers (coldic3)
This PR was merged into the 1.12-dev branch. Discussion ---------- | Q | A | --------------- | ----- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Related tickets | | License | MIT Commits -------b87a91618c[API] Use the Calendar component in command handlerse945d76e29[Maintenance][API] Update UPGRADE-API-1.12.md
This commit is contained in:
commit
642142b434
6 changed files with 51 additions and 10 deletions
|
|
@ -71,3 +71,28 @@ Here is how the response looks like:
|
|||
Wrong parameters otherwise cause empty array `[]` in response and correct parameters return `paymentMethods` available for your `payment`.
|
||||
|
||||
1. The 2nd parameter `MetadataInterface` has been removed from `src/Sylius/Bundle/ApiBundle/CommandHandler/Account/ResetPasswordHandler` and replaced by `Sylius\Component\User\Security\PasswordUpdaterInterface` (previously 3rd parameter). From now on a token TTL value must be used instead as the 3rd parameter.
|
||||
|
||||
1. Constructor of `Sylius\Bundle\ApiBundle\CommandHandler\Account\RequestResetPasswordTokenHandler` has been extended with `Sylius\Calendar\Provider\DateTimeProviderInterface` argument:
|
||||
|
||||
```diff
|
||||
public function __construct(
|
||||
private UserRepositoryInterface $userRepository,
|
||||
private MessageBusInterface $commandBus,
|
||||
- private GeneratorInterface $generator
|
||||
+ private GeneratorInterface $generator,
|
||||
+ private DateTimeProviderInterface $calendar
|
||||
) {
|
||||
}
|
||||
```
|
||||
|
||||
1. Constructor of `\Sylius\Bundle\ApiBundle\CommandHandler\Account\VerifyCustomerAccountHandler` has been extended with `Sylius\Calendar\Provider\DateTimeProviderInterface` argument:
|
||||
|
||||
```diff
|
||||
- public function __construct(private RepositoryInterface $shopUserRepository)
|
||||
- {
|
||||
+ public function __construct(
|
||||
+ private RepositoryInterface $shopUserRepository,
|
||||
+ private DateTimeProviderInterface $calendar
|
||||
+ ) {
|
||||
}
|
||||
```
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Sylius\Bundle\ApiBundle\CommandHandler\Account;
|
|||
|
||||
use Sylius\Bundle\ApiBundle\Command\Account\RequestResetPasswordToken;
|
||||
use Sylius\Bundle\ApiBundle\Command\Account\SendResetPasswordEmail;
|
||||
use Sylius\Calendar\Provider\DateTimeProviderInterface;
|
||||
use Sylius\Component\User\Repository\UserRepositoryInterface;
|
||||
use Sylius\Component\User\Security\Generator\GeneratorInterface;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
|
@ -28,7 +29,8 @@ final class RequestResetPasswordTokenHandler implements MessageHandlerInterface
|
|||
public function __construct(
|
||||
private UserRepositoryInterface $userRepository,
|
||||
private MessageBusInterface $commandBus,
|
||||
private GeneratorInterface $generator
|
||||
private GeneratorInterface $generator,
|
||||
private DateTimeProviderInterface $calendar
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -38,7 +40,7 @@ final class RequestResetPasswordTokenHandler implements MessageHandlerInterface
|
|||
Assert::notNull($user);
|
||||
|
||||
$user->setPasswordResetToken($this->generator->generate());
|
||||
$user->setPasswordRequestedAt(new \DateTime());
|
||||
$user->setPasswordRequestedAt($this->calendar->now());
|
||||
|
||||
$this->commandBus->dispatch(
|
||||
new SendResetPasswordEmail(
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ namespace Sylius\Bundle\ApiBundle\CommandHandler\Account;
|
|||
|
||||
use InvalidArgumentException;
|
||||
use Sylius\Bundle\ApiBundle\Command\Account\VerifyCustomerAccount;
|
||||
use Sylius\Calendar\Provider\DateTimeProviderInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Sylius\Component\User\Model\UserInterface;
|
||||
use Symfony\Component\HttpFoundation\JsonResponse;
|
||||
|
|
@ -23,8 +24,10 @@ use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
|||
/** @experimental */
|
||||
final class VerifyCustomerAccountHandler implements MessageHandlerInterface
|
||||
{
|
||||
public function __construct(private RepositoryInterface $shopUserRepository)
|
||||
{
|
||||
public function __construct(
|
||||
private RepositoryInterface $shopUserRepository,
|
||||
private DateTimeProviderInterface $calendar
|
||||
) {
|
||||
}
|
||||
|
||||
public function __invoke(VerifyCustomerAccount $command): JsonResponse
|
||||
|
|
@ -37,7 +40,7 @@ final class VerifyCustomerAccountHandler implements MessageHandlerInterface
|
|||
);
|
||||
}
|
||||
|
||||
$user->setVerifiedAt(new \DateTime());
|
||||
$user->setVerifiedAt($this->calendar->now());
|
||||
$user->setEmailVerificationToken(null);
|
||||
$user->enable();
|
||||
|
||||
|
|
|
|||
|
|
@ -146,6 +146,7 @@
|
|||
<argument type="service" id="sylius.repository.shop_user" />
|
||||
<argument type="service" id="messenger.default_bus" />
|
||||
<argument type="service" id="sylius.shop_user.token_generator.password_reset" />
|
||||
<argument type="service" id="Sylius\Calendar\Provider\DateTimeProviderInterface" />
|
||||
<tag name="messenger.message_handler" bus="sylius.command_bus" />
|
||||
<tag name="messenger.message_handler" bus="sylius_default.bus" />
|
||||
</service>
|
||||
|
|
@ -206,6 +207,7 @@
|
|||
|
||||
<service id="Sylius\Bundle\ApiBundle\CommandHandler\Account\VerifyCustomerAccountHandler">
|
||||
<argument type="service" id="sylius.repository.shop_user" />
|
||||
<argument type="service" id="Sylius\Calendar\Provider\DateTimeProviderInterface" />
|
||||
<tag name="messenger.message_handler" bus="sylius.command_bus" />
|
||||
<tag name="messenger.message_handler" bus="sylius_default.bus" />
|
||||
</service>
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use PhpSpec\ObjectBehavior;
|
|||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\ApiBundle\Command\Account\RequestResetPasswordToken;
|
||||
use Sylius\Bundle\ApiBundle\Command\Account\SendResetPasswordEmail;
|
||||
use Sylius\Calendar\Provider\DateTimeProviderInterface;
|
||||
use Sylius\Component\Core\Model\ShopUserInterface;
|
||||
use Sylius\Component\User\Repository\UserRepositoryInterface;
|
||||
use Sylius\Component\User\Security\Generator\GeneratorInterface;
|
||||
|
|
@ -30,9 +31,10 @@ final class RequestResetPasswordTokenHandlerSpec extends ObjectBehavior
|
|||
function let(
|
||||
UserRepositoryInterface $userRepository,
|
||||
MessageBusInterface $messageBus,
|
||||
GeneratorInterface $generator
|
||||
GeneratorInterface $generator,
|
||||
DateTimeProviderInterface $dateTimeProvider
|
||||
): void {
|
||||
$this->beConstructedWith($userRepository, $messageBus, $generator);
|
||||
$this->beConstructedWith($userRepository, $messageBus, $generator, $dateTimeProvider);
|
||||
}
|
||||
|
||||
function it_is_a_message_handler(): void
|
||||
|
|
@ -44,9 +46,11 @@ final class RequestResetPasswordTokenHandlerSpec extends ObjectBehavior
|
|||
UserRepositoryInterface $userRepository,
|
||||
ShopUserInterface $shopUser,
|
||||
GeneratorInterface $generator,
|
||||
DateTimeProviderInterface $dateTimeProvider,
|
||||
MessageBusInterface $messageBus
|
||||
): void {
|
||||
$userRepository->findOneByEmail('test@email.com')->willReturn($shopUser);
|
||||
$dateTimeProvider->now()->willReturn(new \DateTime());
|
||||
|
||||
$generator->generate()->willReturn('TOKEN');
|
||||
$shopUser->setPasswordResetToken('TOKEN')->shouldBeCalled();
|
||||
|
|
|
|||
|
|
@ -16,15 +16,18 @@ namespace spec\Sylius\Bundle\ApiBundle\CommandHandler\Account;
|
|||
use PhpSpec\ObjectBehavior;
|
||||
use Prophecy\Argument;
|
||||
use Sylius\Bundle\ApiBundle\Command\Account\VerifyCustomerAccount;
|
||||
use Sylius\Calendar\Provider\DateTimeProviderInterface;
|
||||
use Sylius\Component\Resource\Repository\RepositoryInterface;
|
||||
use Sylius\Component\User\Model\UserInterface;
|
||||
use Symfony\Component\Messenger\Handler\MessageHandlerInterface;
|
||||
|
||||
final class VerifyCustomerAccountHandlerSpec extends ObjectBehavior
|
||||
{
|
||||
function let(RepositoryInterface $shopUserRepository): void
|
||||
{
|
||||
$this->beConstructedWith($shopUserRepository);
|
||||
function let(
|
||||
RepositoryInterface $shopUserRepository,
|
||||
DateTimeProviderInterface $dateTimeProvider
|
||||
): void {
|
||||
$this->beConstructedWith($shopUserRepository, $dateTimeProvider);
|
||||
}
|
||||
|
||||
function it_is_a_message_handler(): void
|
||||
|
|
@ -34,9 +37,11 @@ final class VerifyCustomerAccountHandlerSpec extends ObjectBehavior
|
|||
|
||||
function it_verifies_shop_user(
|
||||
RepositoryInterface $shopUserRepository,
|
||||
DateTimeProviderInterface $dateTimeProvider,
|
||||
UserInterface $user
|
||||
): void {
|
||||
$shopUserRepository->findOneBy(['emailVerificationToken' => 'ToKeN'])->willReturn($user);
|
||||
$dateTimeProvider->now()->willReturn(new \DateTime());
|
||||
|
||||
$user->setVerifiedAt(Argument::type(\DateTime::class))->shouldBeCalled();
|
||||
$user->setEmailVerificationToken(null)->shouldBeCalled();
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue