[UserBundle] Remove pin configuration parameter and related things (#17259)

| Q               | A
|-----------------|-----
| Branch?         | 2.0
| Bug fix?        | no
| New feature?    | no
| BC breaks?      | yes
| Deprecations? | no<!-- don't forget to update the UPGRADE-*.md file
-->
| Related tickets | continuation of #17246 
| License         | MIT

<!--
 - Bug fixes must be submitted against the 1.13 branch
 - Features and deprecations must be submitted against the 1.14 branch
- Features, removing deprecations and BC breaks must be submitted
against the 2.0 branch
 - Make sure that the correct base branch is set

To be sure you are not breaking any Backward Compatibilities, check the
documentation:

https://docs.sylius.com/en/latest/book/organization/backward-compatibility-promise.html
-->
This commit is contained in:
Karol 2024-10-18 07:57:58 +02:00 committed by GitHub
commit bffae5ef99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 8 additions and 248 deletions

View file

@ -9,6 +9,13 @@
* SyliusStateMachineAbstraction:
* The `sylius_state_machine_abstraction.default_adapter` option has been changed from `winzou_state_machine` to `symfony_workflow`.
* The `sylius_user.resources.{name}.user.resetting.pin` configuration parameter has been removed.
The corresponding email `reset_password_pin` and `Sylius\Bundle\UserBundle\Controller\UserController::requestPasswordResetPinAction`
method have been removed. The related services have been removed as well:
* `sylius.{user_type}_user.pin_generator.password_reset`
* `sylius.{user_type}_user.pin_uniqueness_checker.password_reset`
## Dependencies
* The following dependencies have been removed, install them in your application, if you still want to use Winzou State Machine:
@ -449,6 +456,7 @@
* `Sylius\Bundle\UserBundle\Security\UserLoginInterface`
* `Sylius\Bundle\UserBundle\Security\UserPasswordHasher`
* `Sylius\Bundle\UserBundle\Security\UserPasswordHasherInterface`
* `Sylius\Component\User\Security\Generator\UniquePinGenerator`
* The following services and aliases have been removed:

View file

@ -33,9 +33,6 @@ Configuration reference
ttl: P1D
length: 16
field_name: passwordResetToken
pin:
length: 4
field_name: passwordResetToken
verification:
token:
length: 16
@ -56,9 +53,6 @@ Configuration reference
ttl: P1D
length: 16
field_name: passwordResetToken
pin:
length: 4
field_name: passwordResetToken
verification:
token:
length: 16
@ -79,9 +73,6 @@ Configuration reference
ttl: P1D
length: 16
field_name: passwordResetToken
pin:
length: 4
field_name: passwordResetToken
verification:
token:
length: 16

View file

@ -39,12 +39,6 @@ final class MailerListener
$this->sendEmail($event->getSubject(), UserBundleEmails::RESET_PASSWORD_TOKEN);
}
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. */
public function sendResetPasswordPinEmail(GenericEvent $event): void
{
$this->sendEmail($event->getSubject(), UserBundleEmails::RESET_PASSWORD_PIN);
}
public function sendVerificationTokenEmail(GenericEvent $event): void
{
$this->sendEmail($event->getSubject(), UserBundleEmails::EMAIL_VERIFICATION_TOKEN);

View file

@ -19,7 +19,6 @@
<argument type="service" id="sylius.email_sender" />
<argument type="service" id="sylius.context.channel" />
<argument type="service" id="sylius.context.locale" />
<tag name="kernel.event_listener" event="sylius.user.password_reset.request.pin" method="sendResetPasswordPinEmail" />
<tag name="kernel.event_listener" event="sylius.user.password_reset.request.token" method="sendResetPasswordTokenEmail" />
<tag name="kernel.event_listener" event="sylius.user.email_verification.token" method="sendVerificationTokenEmail" />
<tag name="kernel.event_listener" event="sylius.user.post_email_verification" method="sendVerificationSuccessEmail" />

View file

@ -139,25 +139,6 @@ final class MailerListenerSpec extends ObjectBehavior
$this->sendResetPasswordTokenEmail($event);
}
function it_send_password_reset_pin_mail(
SenderInterface $emailSender,
ChannelInterface $channel,
GenericEvent $event,
UserInterface $user,
): void {
$event->getSubject()->willReturn($user);
$user->getEmail()->willReturn('test@example.com');
$emailSender->send('reset_password_pin', ['test@example.com'], [
'user' => $user,
'channel' => $channel,
'localeCode' => 'en_US',
])->shouldBeCalled();
$this->sendResetPasswordPinEmail($event);
}
function it_sends_verification_success_email(
SenderInterface $emailSender,
GenericEvent $event,

View file

@ -18,10 +18,6 @@ sylius_mailer:
reset_password_token:
subject: sylius.emails.user.password_reset.subject
template: "@SyliusShop/email/password_reset.html.twig"
# This email is deprecated since Sylius 1.14 and will be removed in 2.0.
reset_password_pin:
subject: sylius.emails.user.password_reset.subject
template: "@SyliusShop/email/password_reset.html.twig"
verification_token:
subject: sylius.emails.user.verification_token.subject
template: "@SyliusShop/email/verification.html.twig"

View file

@ -72,15 +72,6 @@ class UserController extends ResourceController
return $this->prepareResetPasswordRequest($request, $generator, UserEvents::REQUEST_RESET_PASSWORD_TOKEN);
}
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. */
public function requestPasswordResetPinAction(Request $request): Response
{
/** @var GeneratorInterface $generator */
$generator = $this->container->get(sprintf('sylius.%s.pin_generator.password_reset', $this->metadata->getName()));
return $this->prepareResetPasswordRequest($request, $generator, UserEvents::REQUEST_RESET_PASSWORD_PIN);
}
public function resetPasswordAction(Request $request, string $token): Response
{
$configuration = $this->requestConfigurationFactory->create($this->metadata, $request);

View file

@ -99,28 +99,6 @@ final class Configuration implements ConfigurationInterface
->end()
->end()
->end()
->arrayNode('pin')
->setDeprecated('sylius/user-bundle', '1.14', 'The "%path%.%node%" is deprecated and will be removed in 2.0.')
->addDefaultsIfNotSet()
->children()
->integerNode('length')
->defaultValue(4)
->min(1)->max(9)
->end()
->scalarNode('field_name')
->defaultValue('passwordResetToken')
->validate()
->ifTrue(
/** @param mixed $passwordResetToken */
function ($passwordResetToken) {
return !is_string($passwordResetToken);
},
)
->thenInvalid('Invalid resetting pin field "%s"')
->end()
->end()
->end()
->end()
->end()
->end()
->arrayNode('verification')

View file

@ -23,7 +23,6 @@ use Sylius\Bundle\UserBundle\Provider\UsernameOrEmailProvider;
use Sylius\Bundle\UserBundle\Provider\UsernameProvider;
use Sylius\Bundle\UserBundle\Reloader\UserReloader;
use Sylius\Component\User\Security\Checker\TokenUniquenessChecker;
use Sylius\Component\User\Security\Generator\UniquePinGenerator;
use Sylius\Component\User\Security\Generator\UniqueTokenGenerator;
use Symfony\Component\Config\FileLocator;
use Symfony\Component\DependencyInjection\ChildDefinition;
@ -101,22 +100,6 @@ final class SyliusUserExtension extends AbstractResourceExtension
),
)->setPublic(true);
$container
->setDefinition(
sprintf('sylius.%s_user.pin_generator.password_reset', $userType),
$this->createTokenGeneratorDefinition(
UniquePinGenerator::class,
[
new Reference('sylius.random_generator'),
new Reference(sprintf('sylius.%s_user.pin_uniqueness_checker.password_reset', $userType)),
$config['resetting']['pin']['length'],
],
),
)
->setPublic(true)
->setDeprecated('sylius/user-bundle', '1.14', 'The "%service_id%" is deprecated and will be removed in Sylius 2.0.')
;
$container
->setDefinition(
sprintf('sylius.%s_user.token_generator.email_verification', $userType),
@ -130,7 +113,6 @@ final class SyliusUserExtension extends AbstractResourceExtension
),
)
->setPublic(true)
->setDeprecated('sylius/user-bundle', '1.14', 'The "%service_id%" is deprecated and will be removed in Sylius 2.0.')
;
}
@ -154,14 +136,6 @@ final class SyliusUserExtension extends AbstractResourceExtension
$resetPasswordTokenUniquenessCheckerDefinition,
);
$resetPasswordPinUniquenessCheckerDefinition = new Definition(TokenUniquenessChecker::class);
$resetPasswordPinUniquenessCheckerDefinition->addArgument(new Reference($repositoryServiceId));
$resetPasswordPinUniquenessCheckerDefinition->addArgument($config['resetting']['pin']['field_name']);
$container->setDefinition(
sprintf('sylius.%s_user.pin_uniqueness_checker.password_reset', $userType),
$resetPasswordPinUniquenessCheckerDefinition,
);
$emailVerificationTokenUniquenessCheckerDefinition = new Definition(TokenUniquenessChecker::class);
$emailVerificationTokenUniquenessCheckerDefinition->addArgument(new Reference($repositoryServiceId));
$emailVerificationTokenUniquenessCheckerDefinition->addArgument($config['verification']['token']['field_name']);

View file

@ -30,12 +30,6 @@ class MailerListener
$this->sendEmail($event->getSubject(), Emails::RESET_PASSWORD_TOKEN);
}
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. */
public function sendResetPasswordPinEmail(GenericEvent $event): void
{
$this->sendEmail($event->getSubject(), Emails::RESET_PASSWORD_PIN);
}
public function sendVerificationTokenEmail(GenericEvent $event): void
{
$this->sendEmail($event->getSubject(), Emails::EMAIL_VERIFICATION_TOKEN);

View file

@ -17,8 +17,5 @@ final class Emails
{
public const RESET_PASSWORD_TOKEN = 'reset_password_token';
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. */
public const RESET_PASSWORD_PIN = 'reset_password_pin';
public const EMAIL_VERIFICATION_TOKEN = 'verification_token';
}

View file

@ -75,7 +75,6 @@
<service id="sylius.listener.user_mailer_listener" class="Sylius\Bundle\UserBundle\EventListener\MailerListener">
<argument type="service" id="sylius.email_sender" />
<tag name="kernel.event_listener" event="sylius.user.password_reset.request.pin" method="sendResetPasswordPinEmail" />
<tag name="kernel.event_listener" event="sylius.user.password_reset.request.token" method="sendResetPasswordTokenEmail" />
<tag name="kernel.event_listener" event="sylius.user.email_verification.token" method="sendVerificationTokenEmail" />
</service>

View file

@ -36,10 +36,6 @@ final class ConfigurationTest extends TestCase
'length' => 64,
'field_name' => 'passwordResetToken',
],
'pin' => [
'length' => 4,
'field_name' => 'passwordResetToken',
],
],
],
],

View file

@ -17,9 +17,6 @@ interface UserEvents
{
public const REQUEST_RESET_PASSWORD_TOKEN = 'sylius.user.password_reset.request.token';
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. */
public const REQUEST_RESET_PASSWORD_PIN = 'sylius.user.password_reset.request.pin';
public const REQUEST_VERIFICATION_TOKEN = 'sylius.user.email_verification.token';
public const PRE_EMAIL_VERIFICATION = 'sylius.user.pre_email_verification';

View file

@ -1,52 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace Sylius\Component\User\Security\Generator;
use Sylius\Component\User\Security\Checker\UniquenessCheckerInterface;
use Sylius\Resource\Generator\RandomnessGeneratorInterface;
use Webmozart\Assert\Assert;
trigger_deprecation(
'sylius/user',
'1.14',
'The "%s" class is deprecated and will be removed in Sylius 2.0.',
UniquePinGenerator::class,
);
/** @deprecated since Sylius 1.14 and will be removed in Sylius 2.0. */
final class UniquePinGenerator implements GeneratorInterface
{
private int $pinLength;
/**
* @throws \InvalidArgumentException
*/
public function __construct(
private RandomnessGeneratorInterface $generator,
private UniquenessCheckerInterface $uniquenessChecker,
int $pinLength,
) {
Assert::greaterThanEq($pinLength, 1, 'The value of token length has to be at least 1.');
$this->pinLength = $pinLength;
}
public function generate(): string
{
do {
$pin = $this->generator->generateNumeric($this->pinLength);
} while (!$this->uniquenessChecker->isUnique($pin));
return $pin;
}
}

View file

@ -1,83 +0,0 @@
<?php
/*
* This file is part of the Sylius package.
*
* (c) Sylius Sp. z o.o.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
declare(strict_types=1);
namespace spec\Sylius\Component\User\Security\Generator;
use PhpSpec\ObjectBehavior;
use Sylius\Component\User\Security\Checker\UniquenessCheckerInterface;
use Sylius\Component\User\Security\Generator\GeneratorInterface;
use Sylius\Resource\Generator\RandomnessGeneratorInterface;
final class UniquePinGeneratorSpec extends ObjectBehavior
{
function let(RandomnessGeneratorInterface $generator, UniquenessCheckerInterface $checker): void
{
$this->beConstructedWith($generator, $checker, 6);
}
function it_implements_generator_interface(): void
{
$this->shouldImplement(GeneratorInterface::class);
}
function it_throws_invalid_argument_exception_on_instantiation_with_an_out_of_range_length(
RandomnessGeneratorInterface $generator,
UniquenessCheckerInterface $checker,
): void {
$this->beConstructedWith($generator, $checker, -1);
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation();
$this->beConstructedWith($generator, $checker, 0);
$this->shouldThrow(\InvalidArgumentException::class)->duringInstantiation();
}
function it_generates_pins_with_length_stated_on_instantiation(
RandomnessGeneratorInterface $generator,
UniquenessCheckerInterface $checker,
): void {
$pin = '001100';
$generator->generateNumeric(6)->willReturn($pin);
$checker->isUnique($pin)->willReturn(true);
$this->generate()->shouldHaveLength(6);
}
function it_generates_string_pins(RandomnessGeneratorInterface $generator, UniquenessCheckerInterface $checker): void
{
$pin = '636363';
$generator->generateNumeric(6)->willReturn($pin);
$checker->isUnique($pin)->willReturn(true);
$this->generate()->shouldBeString();
}
function it_generates_numeric_pins(RandomnessGeneratorInterface $generator, UniquenessCheckerInterface $checker): void
{
$pin = '424242';
$generator->generateNumeric(6)->willReturn($pin);
$checker->isUnique($pin)->willReturn(true);
$this->generate()->shouldBeNumeric();
}
public function getMatchers(): array
{
return [
'haveLength' => function ($subject, $key) {
return $key === strlen($subject);
},
];
}
}