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