From b3d57d4b7d37d37038ab2da55e43a47a61547a29 Mon Sep 17 00:00:00 2001 From: Reyo Stallenberg Date: Thu, 3 Oct 2019 14:24:07 +0200 Subject: [PATCH 1/2] Make sf3.4 compatible --- src/Command/UserCreateCommand.php | 10 +++++----- src/Controller/RegistrationController.php | 11 ++++++----- src/Controller/SecurityController.php | 2 +- src/Event/CreateUserEvent.php | 2 +- src/Event/UserCreatedEvent.php | 2 +- src/Mailer/BaseEmail.php | 5 ----- src/Resources/views/emails/registration.html.twig | 2 +- .../views/{security => forms}/login.html.twig | 0 .../views/{registration => forms}/register.html.twig | 0 9 files changed, 15 insertions(+), 19 deletions(-) rename src/Resources/views/{security => forms}/login.html.twig (100%) rename src/Resources/views/{registration => forms}/register.html.twig (100%) diff --git a/src/Command/UserCreateCommand.php b/src/Command/UserCreateCommand.php index 44a7901..e1e462b 100644 --- a/src/Command/UserCreateCommand.php +++ b/src/Command/UserCreateCommand.php @@ -12,14 +12,14 @@ use ConnectHolland\UserBundle\Entity\User; use ConnectHolland\UserBundle\Event\CreateUserEvent; use ConnectHolland\UserBundle\Event\UserCreatedEvent; +use ConnectHolland\UserBundle\UserBundleEvents; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; -use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; class UserCreateCommand extends Command { @@ -34,7 +34,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher) { parent::__construct(); - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher) ?? $eventDispatcher; + $this->eventDispatcher = $eventDispatcher; } protected function configure() @@ -63,10 +63,10 @@ protected function execute(InputInterface $input, OutputInterface $output) $enable = $input->getOption('inactive') !== true; /** @var CreateUserEvent $event */ - $event = $this->eventDispatcher->dispatch(new CreateUserEvent((new User())->setEmail($email)->setEnabled($enable), $password)); + $event = $this->eventDispatcher->dispatch(UserBundleEvents::CREATE_USER, new CreateUserEvent((new User())->setEmail($email)->setEnabled($enable), $password)); if ($event->isPropagationStopped() === false) { /** @var UserCreatedEvent $event */ - $event = $this->eventDispatcher->dispatch(new UserCreatedEvent($event->getUser())); + $event = $this->eventDispatcher->dispatch(UserBundleEvents::USER_CREATED, new UserCreatedEvent($event->getUser())); if ($event->isPropagationStopped() === false) { $output->writeln(sprintf('Created user %s', $email)); } diff --git a/src/Controller/RegistrationController.php b/src/Controller/RegistrationController.php index 456b912..42a57f3 100644 --- a/src/Controller/RegistrationController.php +++ b/src/Controller/RegistrationController.php @@ -16,6 +16,7 @@ use ConnectHolland\UserBundle\Form\RegistrationType; use ConnectHolland\UserBundle\Repository\UserRepository; use ConnectHolland\UserBundle\Security\UserBundleAuthenticator; +use ConnectHolland\UserBundle\UserBundleEvents; use Doctrine\ORM\EntityManagerInterface; use Symfony\Bridge\Doctrine\RegistryInterface; use Symfony\Component\EventDispatcher\LegacyEventDispatcherProxy; @@ -28,7 +29,7 @@ use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\RouterInterface; use Symfony\Component\Security\Guard\GuardAuthenticatorHandler; -use Symfony\Contracts\EventDispatcher\EventDispatcherInterface; +use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Twig\Environment; class RegistrationController @@ -62,7 +63,7 @@ public function __construct(RegistryInterface $registry, Session $session, Event { $this->registry = $registry; $this->session = $session; - $this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher) ?? $eventDispatcher; + $this->eventDispatcher = $eventDispatcher; $this->router = $router; $this->twig = $twig; } @@ -77,10 +78,10 @@ public function register(Request $request, FormFactoryInterface $formFactory): R if ($form->isSubmitted() && $form->isValid()) { /** @var CreateUserEvent $event */ - $event = $this->eventDispatcher->dispatch(new CreateUserEvent($form->getData(), $form->get('plainPassword')->getData())); + $event = $this->eventDispatcher->dispatch(UserBundleEvents::CREATE_USER, new CreateUserEvent($form->getData(), $form->get('plainPassword')->getData())); if ($event->isPropagationStopped() === false) { /** @var UserCreatedEvent $event */ - $event = $this->eventDispatcher->dispatch(new UserCreatedEvent($event->getUser())); + $event = $this->eventDispatcher->dispatch(UserBundleEvents::USER_CREATED, new UserCreatedEvent($event->getUser())); if ($event->isPropagationStopped() === false) { $this->session->getFlashBag()->add('notice', 'Check your e-mail to complete your registration'); @@ -91,7 +92,7 @@ public function register(Request $request, FormFactoryInterface $formFactory): R return new Response( $this->twig->render( - '@ConnecthollandUser/registration/register.html.twig', + '@ConnecthollandUser/forms/register.html.twig', [ 'form' => $form->createView(), ] diff --git a/src/Controller/SecurityController.php b/src/Controller/SecurityController.php index e55f824..9ae3124 100644 --- a/src/Controller/SecurityController.php +++ b/src/Controller/SecurityController.php @@ -43,7 +43,7 @@ public function __construct(AuthenticationUtils $authenticationUtils, FormFactor /** * @Route("/inloggen", name="connectholland_user_login", methods={"GET", "POST"}) */ - public function login(): Response + public function __invoke(): Response { $form = $this->formFactory->create(LoginType::class); $lastUsername = $this->authenticationUtils->getLastUsername(); diff --git a/src/Event/CreateUserEvent.php b/src/Event/CreateUserEvent.php index 310c3df..47c10b8 100644 --- a/src/Event/CreateUserEvent.php +++ b/src/Event/CreateUserEvent.php @@ -10,7 +10,7 @@ namespace ConnectHolland\UserBundle\Event; use ConnectHolland\UserBundle\Entity\UserInterface; -use Symfony\Contracts\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\Event; class CreateUserEvent extends Event { diff --git a/src/Event/UserCreatedEvent.php b/src/Event/UserCreatedEvent.php index bff09bd..f359ab1 100644 --- a/src/Event/UserCreatedEvent.php +++ b/src/Event/UserCreatedEvent.php @@ -10,7 +10,7 @@ namespace ConnectHolland\UserBundle\Event; use ConnectHolland\UserBundle\Entity\UserInterface; -use Symfony\Contracts\EventDispatcher\Event; +use Symfony\Component\EventDispatcher\Event; class UserCreatedEvent extends Event { diff --git a/src/Mailer/BaseEmail.php b/src/Mailer/BaseEmail.php index 4967a48..a7546e7 100755 --- a/src/Mailer/BaseEmail.php +++ b/src/Mailer/BaseEmail.php @@ -15,11 +15,6 @@ abstract class BaseEmail * @var Mailer */ protected $mailer; -// -// public function __construct(Mailer $mailer) -// { -// $this->mailer = $mailer; -// } public function setMailer(Mailer $mailer): void { diff --git a/src/Resources/views/emails/registration.html.twig b/src/Resources/views/emails/registration.html.twig index dd65816..5195059 100644 --- a/src/Resources/views/emails/registration.html.twig +++ b/src/Resources/views/emails/registration.html.twig @@ -6,7 +6,7 @@ {% block body %}

Registration

- Bevestigen + Confirm registration {% endblock %} diff --git a/src/Resources/views/security/login.html.twig b/src/Resources/views/forms/login.html.twig similarity index 100% rename from src/Resources/views/security/login.html.twig rename to src/Resources/views/forms/login.html.twig diff --git a/src/Resources/views/registration/register.html.twig b/src/Resources/views/forms/register.html.twig similarity index 100% rename from src/Resources/views/registration/register.html.twig rename to src/Resources/views/forms/register.html.twig From c13e2b7b9cd9d75205d5fcd19ef37046be5407cb Mon Sep 17 00:00:00 2001 From: Reyo Stallenberg Date: Thu, 3 Oct 2019 15:26:39 +0200 Subject: [PATCH 2/2] Fix projectDirectory and USERBUNDLE_FROM_EMAILADDRESS --- README.md | 8 ++++++++ src/Mailer/Mailer.php | 14 ++++---------- src/Resources/config/services.yaml | 1 - 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index d499454..eb8934a 100644 --- a/README.md +++ b/README.md @@ -14,3 +14,11 @@ This bundle will be extendible and provide: - Recover password functionality - Being API accessable - Ability to 'switch on' OAuth (Google/GitHub/Facebook/etc) + +## Environment + +Set the environment variables to be able to send e-mails. + +```dotenv +USERBUNDLE_FROM_EMAILADDRESS=example@example.com +``` diff --git a/src/Mailer/Mailer.php b/src/Mailer/Mailer.php index 2a01502..a77fdf8 100644 --- a/src/Mailer/Mailer.php +++ b/src/Mailer/Mailer.php @@ -30,17 +30,11 @@ class Mailer */ private $twig; - /** - * @var string - */ - private $projectDirectory; - - public function __construct(\Swift_Mailer $mailer, string $fromEmail, Environment $twig, string $projectDirectory) + public function __construct(\Swift_Mailer $mailer, string $fromEmail, Environment $twig) { - $this->mailer = $mailer; - $this->fromEmail = $fromEmail; - $this->twig = $twig; - $this->projectDirectory = $projectDirectory; + $this->mailer = $mailer; + $this->fromEmail = $fromEmail; + $this->twig = $twig; } public function createMessageAndSend(string $name, $to, array $parameters = []): \Swift_Message diff --git a/src/Resources/config/services.yaml b/src/Resources/config/services.yaml index 350d9ac..575e76a 100644 --- a/src/Resources/config/services.yaml +++ b/src/Resources/config/services.yaml @@ -22,7 +22,6 @@ services: - '@mailer' - '%env(USERBUNDLE_FROM_EMAILADDRESS)%' - '@twig' - - '%kernel.project_dir%' ConnectHolland\UserBundle\Mailer\RegistrationEmail: arguments: