Skip to content

Commit

Permalink
Sf3.4 compatibility (#5)
Browse files Browse the repository at this point in the history
Sf3.4 compatibility
  • Loading branch information
reyostallenberg committed Oct 7, 2019
2 parents 3702017 + c13e2b7 commit 9b0207d
Show file tree
Hide file tree
Showing 12 changed files with 27 additions and 30 deletions.
8 changes: 8 additions & 0 deletions README.md
Expand Up @@ -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
```
10 changes: 5 additions & 5 deletions src/Command/UserCreateCommand.php
Expand Up @@ -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
{
Expand All @@ -34,7 +34,7 @@ public function __construct(EventDispatcherInterface $eventDispatcher)
{
parent::__construct();

$this->eventDispatcher = LegacyEventDispatcherProxy::decorate($eventDispatcher) ?? $eventDispatcher;
$this->eventDispatcher = $eventDispatcher;
}

protected function configure()
Expand Down Expand Up @@ -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 <comment>%s</comment>', $email));
}
Expand Down
11 changes: 6 additions & 5 deletions src/Controller/RegistrationController.php
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand All @@ -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');

Expand All @@ -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(),
]
Expand Down
2 changes: 1 addition & 1 deletion src/Controller/SecurityController.php
Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/Event/CreateUserEvent.php
Expand Up @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Event/UserCreatedEvent.php
Expand Up @@ -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
{
Expand Down
5 changes: 0 additions & 5 deletions src/Mailer/BaseEmail.php
Expand Up @@ -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
{
Expand Down
14 changes: 4 additions & 10 deletions src/Mailer/Mailer.php
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/Resources/config/services.yaml
Expand Up @@ -22,7 +22,6 @@ services:
- '@mailer'
- '%env(USERBUNDLE_FROM_EMAILADDRESS)%'
- '@twig'
- '%kernel.project_dir%'

ConnectHolland\UserBundle\Mailer\RegistrationEmail:
arguments:
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/views/emails/registration.html.twig
Expand Up @@ -6,7 +6,7 @@
<body>
{% block body %}
<h1>Registration</h1>
<a href='{{ link }}'>Bevestigen</a>
<a href='{{ link }}'>Confirm registration</a>
{% endblock %}
</body>
</htmL>
File renamed without changes.

0 comments on commit 9b0207d

Please sign in to comment.