Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump nucleos/user-bundle #436

Merged
merged 5 commits into from
Dec 29, 2021
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
28 changes: 28 additions & 0 deletions UPGRADE-2.0.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
UPGRADE FROM 1.x to 2.0
=======================

## Removed XML configurations

All configuration files were migrated to PHP to improve overall performance.

The `@NucleosProfileBundle/Resources/config/routing/all.xml` routing configuration was removed.

## Remove listeners configuration

All listeneres are now registered by default. The `use_authentication_listener`, `use_listener` and `use_flash_notifications` configuration keys were removed.

## Removed `Interface` suffix

The `Interface` suffix was removed from all interfaces. All default implementation use specific class prefix.

- `Nucleos\ProfileBundle\Mailer\MailerInterface` => `Nucleos\ProfileBundle\Mailer\RegistrationMailer`
- `Nucleos\ProfileBundle\Mailer\NoopMailer` => `Nucleos\ProfileBundle\Mailer\NoopRegistrationMailer`
- `Nucleos\ProfileBundle\Mailer\Mailer` => `Nucleos\ProfileBundle\Mailer\SimpleRegistrationMailer`
-
## Deprecations

All the deprecated code introduced on 1.8.x is removed on 2.0.

Please read [1.8.x](https://github.com/nucleos/NucleosProfileBundle/tree/1.8.x) upgrade guides for more information.

See also the [diff code](https://github.com/nucleos/NucleosProfileBundle/compare/1.8.x...2.0.0).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"require": {
"php": "^8.0",
"doctrine/persistence": "^2.2.2",
"nucleos/user-bundle": "^1.7",
"nucleos/user-bundle": "^2.0",
"symfony/config": "^5.4",
"symfony/dependency-injection": "^5.4",
"symfony/event-dispatcher": "^5.4",
Expand Down
5 changes: 1 addition & 4 deletions docs/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ All available configuration options are listed below with their default values.
.. code-block:: yaml

nucleos_profile:
use_listener: true
use_flash_notifications: true
use_authentication_listener: true
registration:
confirmation:
from_email: ~ # Required
enabled: false # change to true for required email confirmation
service:
mailer: nucleos_profile.mailer.default
mailer: nucleos_profile.mailer.simple
2 changes: 1 addition & 1 deletion docs/mailing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Default Mailer Implementations
The bundle comes with three mailer implementations. They are listed below
by service id:

- ``nucleos_profile.mailer.default`` is the default implementation, and uses symfony mailer to send emails.
- ``nucleos_profile.mailer.simple`` is the default implementation, and uses symfony mailer to send emails.
- ``nucleos_profile.mailer.noop`` is a mailer implementation which performs no operation, so no emails are sent.

Configuring the Sender Email Address
Expand Down
6 changes: 3 additions & 3 deletions src/Action/CheckRegistrationMailAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Nucleos\ProfileBundle\Action;

use Nucleos\UserBundle\Model\UserManagerInterface;
use Nucleos\UserBundle\Model\UserManager;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -20,13 +20,13 @@

final class CheckRegistrationMailAction
{
private UserManagerInterface $userManager;
private UserManager $userManager;

private Environment $twig;

private RouterInterface $router;

public function __construct(UserManagerInterface $userManager, Environment $twig, RouterInterface $router)
public function __construct(UserManager $userManager, Environment $twig, RouterInterface $router)
{
$this->userManager = $userManager;
$this->twig = $twig;
Expand Down
6 changes: 3 additions & 3 deletions src/Action/ConfirmRegistrationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Nucleos\ProfileBundle\NucleosProfileEvents;
use Nucleos\UserBundle\Event\FilterUserResponseEvent;
use Nucleos\UserBundle\Event\GetResponseUserEvent;
use Nucleos\UserBundle\Model\UserManagerInterface;
use Nucleos\UserBundle\Model\UserManager;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
Expand All @@ -25,13 +25,13 @@ final class ConfirmRegistrationAction
{
private EventDispatcherInterface $eventDispatcher;

private UserManagerInterface $userManager;
private UserManager $userManager;

private RouterInterface $router;

public function __construct(
EventDispatcherInterface $eventDispatcher,
UserManagerInterface $userManager,
UserManager $userManager,
RouterInterface $router
) {
$this->eventDispatcher = $eventDispatcher;
Expand Down
6 changes: 3 additions & 3 deletions src/Action/EditProfileAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Nucleos\UserBundle\Event\FilterUserResponseEvent;
use Nucleos\UserBundle\Event\GetResponseUserEvent;
use Nucleos\UserBundle\Model\UserInterface;
use Nucleos\UserBundle\Model\UserManagerInterface;
use Nucleos\UserBundle\Model\UserManager;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
Expand All @@ -36,7 +36,7 @@ final class EditProfileAction

private FormFactoryInterface $formFactory;

private UserManagerInterface $userManager;
private UserManager $userManager;

private Environment $twig;

Expand All @@ -47,7 +47,7 @@ final class EditProfileAction
public function __construct(
EventDispatcherInterface $eventDispatcher,
FormFactoryInterface $formFactory,
UserManagerInterface $userManager,
UserManager $userManager,
Environment $twig,
RouterInterface $router,
Security $security
Expand Down
6 changes: 3 additions & 3 deletions src/Action/RegistrationAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Nucleos\UserBundle\Event\FilterUserResponseEvent;
use Nucleos\UserBundle\Event\FormEvent;
use Nucleos\UserBundle\Model\UserInterface;
use Nucleos\UserBundle\Model\UserManagerInterface;
use Nucleos\UserBundle\Model\UserManager;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\FormFactoryInterface;
use Symfony\Component\Form\FormInterface;
Expand All @@ -35,7 +35,7 @@ final class RegistrationAction

private FormFactoryInterface $formFactory;

private UserManagerInterface $userManager;
private UserManager $userManager;

private Environment $twig;

Expand All @@ -44,7 +44,7 @@ final class RegistrationAction
public function __construct(
EventDispatcherInterface $eventDispatcher,
FormFactoryInterface $formFactory,
UserManagerInterface $userManager,
UserManager $userManager,
RouterInterface $router,
Environment $twig
) {
Expand Down
10 changes: 1 addition & 9 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ public function getConfigTreeBuilder(): TreeBuilder

$rootNode = $treeBuilder->getRootNode();

$rootNode
->children()
->booleanNode('use_authentication_listener')->defaultTrue()->end()
->booleanNode('use_listener')->defaultTrue()->end()
->booleanNode('use_flash_notifications')->defaultTrue()->end()
->end()
;

$this->addRegistrationSection($rootNode);
$this->addServiceSection($rootNode);

Expand Down Expand Up @@ -71,7 +63,7 @@ private function addServiceSection(ArrayNodeDefinition $node): void
->arrayNode('service')
->addDefaultsIfNotSet()
->children()
->scalarNode('mailer')->defaultValue('nucleos_profile.mailer.default')->end()
->scalarNode('mailer')->defaultValue('nucleos_profile.mailer.simple')->end()
->end()
->end()
->end()
Expand Down
14 changes: 2 additions & 12 deletions src/DependencyInjection/NucleosProfileExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,8 @@ public function load(array $configs, ContainerBuilder $container): void
$config = $processor->processConfiguration($configuration, $configs);

$loader = new PhpFileLoader($container, new FileLocator(__DIR__.'/../Resources/config'));

foreach (['mailer', 'listeners'] as $basename) {
$loader->load(sprintf('%s.php', $basename));
}

if (!$config['use_authentication_listener']) {
$container->removeDefinition('nucleos_profile.listener.authentication');
}

if ($config['use_flash_notifications']) {
$loader->load('flash_notifications.php');
}
$loader->load('mailer.php');
$loader->load('listeners.php');

$this->loadRegistration($config['registration'], $container, $loader);
$this->loadProfile($loader);
Expand Down
6 changes: 3 additions & 3 deletions src/EventListener/AuthenticationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@
use Nucleos\UserBundle\Event\FilterUserResponseEvent;
use Nucleos\UserBundle\Event\UserEvent;
use Nucleos\UserBundle\NucleosUserEvents;
use Nucleos\UserBundle\Security\LoginManagerInterface;
use Nucleos\UserBundle\Security\LoginManager;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\Security\Core\Exception\AccountStatusException;
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;

final class AuthenticationListener implements EventSubscriberInterface
{
private LoginManagerInterface $loginManager;
private LoginManager $loginManager;

private string $firewallName;

public function __construct(LoginManagerInterface $loginManager, string $firewallName)
public function __construct(LoginManager $loginManager, string $firewallName)
{
$this->loginManager = $loginManager;
$this->firewallName = $firewallName;
Expand Down
12 changes: 6 additions & 6 deletions src/EventListener/EmailConfirmationListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,27 @@
namespace Nucleos\ProfileBundle\EventListener;

use Nucleos\ProfileBundle\Event\UserFormEvent;
use Nucleos\ProfileBundle\Mailer\MailerInterface;
use Nucleos\ProfileBundle\Mailer\RegistrationMailer;
use Nucleos\ProfileBundle\NucleosProfileEvents;
use Nucleos\UserBundle\Util\TokenGeneratorInterface;
use Nucleos\UserBundle\Util\TokenGenerator;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

final class EmailConfirmationListener implements EventSubscriberInterface
{
private MailerInterface $mailer;
private RegistrationMailer $mailer;

private TokenGeneratorInterface $tokenGenerator;
private TokenGenerator $tokenGenerator;

private UrlGeneratorInterface $router;

private SessionInterface $session;

public function __construct(
MailerInterface $mailer,
TokenGeneratorInterface $tokenGenerator,
RegistrationMailer $mailer,
TokenGenerator $tokenGenerator,
UrlGeneratorInterface $router,
SessionInterface $session
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* It is used when the 'email' configuration is not set,
* and allows to use this bundle without swiftmailer.
*/
final class NoopMailer implements MailerInterface
final class NoopRegistrationMailer implements RegistrationMailer
{
public function sendConfirmationEmailMessage(UserInterface $user): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use Nucleos\UserBundle\Model\UserInterface;

interface MailerInterface
interface RegistrationMailer
{
/**
* Send an email to a user to confirm the account creation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
use Symfony\Contracts\Translation\TranslatorInterface;

final class Mailer implements MailerInterface
final class SimpleRegistrationMailer implements RegistrationMailer
{
private SymfonyMailer $mailer;

Expand All @@ -46,11 +46,9 @@ public function __construct(
*/
public function sendConfirmationEmailMessage(UserInterface $user): void
{
$url = $this->router->generate(
'nucleos_profile_registration_confirm',
['token' => $user->getConfirmationToken()],
UrlGeneratorInterface::ABSOLUTE_URL
);
$url = $this->router->generate('nucleos_profile_registration_confirm', [
'token' => $user->getConfirmationToken(),
], UrlGeneratorInterface::ABSOLUTE_URL);

$mail = (new RegistrationMail())
->to(new Address($user->getEmail()))
Expand All @@ -62,7 +60,7 @@ public function sendConfirmationEmailMessage(UserInterface $user): void
;

if (null !== $this->fromEmail) {
$mail->from(Address::fromString($this->fromEmail));
$mail->from(new Address($this->fromEmail));
}

$this->mailer->send($mail);
Expand Down
28 changes: 0 additions & 28 deletions src/Resources/config/flash_notifications.php

This file was deleted.

7 changes: 7 additions & 0 deletions src/Resources/config/listeners.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

use Nucleos\ProfileBundle\EventListener\AlreadyLoggedinListener;
use Nucleos\ProfileBundle\EventListener\AuthenticationListener;
use Nucleos\ProfileBundle\EventListener\FlashListener;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;

Expand All @@ -33,5 +34,11 @@
new Reference('router'),
])

->set(FlashListener::class)
->tag('kernel.event_subscriber')
->args([
new Reference('session.flash_bag'),
new Reference('translator'),
])
;
};
8 changes: 4 additions & 4 deletions src/Resources/config/mailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,23 +11,23 @@

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use Nucleos\ProfileBundle\Mailer\Mailer;
use Nucleos\ProfileBundle\Mailer\NoopMailer;
use Nucleos\ProfileBundle\Mailer\NoopRegistrationMailer;
use Nucleos\ProfileBundle\Mailer\SimpleRegistrationMailer;
use Symfony\Component\DependencyInjection\Parameter;
use Symfony\Component\DependencyInjection\Reference;

return static function (ContainerConfigurator $container): void {
$container->services()

->set('nucleos_profile.mailer.default', Mailer::class)
->set('nucleos_profile.mailer.simple', SimpleRegistrationMailer::class)
->args([
new Reference('mailer.mailer'),
new Reference('translator'),
new Reference('router'),
new Parameter('nucleos_profile.registration.confirmation.from_email'),
])

->set('nucleos_profile.mailer.noop', NoopMailer::class)
->set('nucleos_profile.mailer.noop', NoopRegistrationMailer::class)

;
};
5 changes: 0 additions & 5 deletions src/Resources/config/routing/all.xml

This file was deleted.

Loading