diff options
Diffstat (limited to 'src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php')
-rw-r--r-- | src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php b/src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php new file mode 100644 index 00000000..7c2826ec --- /dev/null +++ b/src/Wallabag/CoreBundle/EventListener/AuthenticationListener.php | |||
@@ -0,0 +1,44 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\EventListener; | ||
4 | |||
5 | use FOS\UserBundle\FOSUserEvents; | ||
6 | use Symfony\Component\DependencyInjection\Container; | ||
7 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
8 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
9 | use FOS\UserBundle\Event\FilterUserResponseEvent; | ||
10 | use Wallabag\CoreBundle\Entity\Config; | ||
11 | |||
12 | class AuthenticationListener implements EventSubscriberInterface | ||
13 | { | ||
14 | private $em; | ||
15 | private $container; | ||
16 | |||
17 | public function __construct(Container $container, $em) | ||
18 | { | ||
19 | $this->container = $container; | ||
20 | $this->em = $em; | ||
21 | } | ||
22 | |||
23 | public static function getSubscribedEvents() | ||
24 | { | ||
25 | return array( | ||
26 | FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate', | ||
27 | ); | ||
28 | } | ||
29 | |||
30 | public function authenticate(FilterUserResponseEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) | ||
31 | { | ||
32 | if (!$event->getUser()->isEnabled()) { | ||
33 | return; | ||
34 | } | ||
35 | |||
36 | $config = new Config($event->getUser()); | ||
37 | $config->setTheme($this->container->getParameter('theme')); | ||
38 | $config->setItemsPerPage($this->container->getParameter('items_on_page')); | ||
39 | $config->setRssLimit($this->container->getParameter('rss_limit')); | ||
40 | $config->setLanguage($this->container->getParameter('language')); | ||
41 | $this->em->persist($config); | ||
42 | $this->em->flush(); | ||
43 | } | ||
44 | } | ||