]>
Commit | Line | Data |
---|---|---|
fcb1fba5 NL |
1 | <?php |
2 | ||
3 | namespace Wallabag\CoreBundle\EventListener; | |
4 | ||
772d8c4b | 5 | use Doctrine\ORM\EntityManager; |
fcb1fba5 | 6 | use FOS\UserBundle\Event\FilterUserResponseEvent; |
772d8c4b | 7 | use FOS\UserBundle\FOSUserEvents; |
619cc453 JB |
8 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
9 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | |
fcb1fba5 NL |
10 | use Wallabag\CoreBundle\Entity\Config; |
11 | ||
359b3f43 | 12 | class RegistrationConfirmedListener implements EventSubscriberInterface |
fcb1fba5 NL |
13 | { |
14 | private $em; | |
772d8c4b JB |
15 | private $theme; |
16 | private $itemsOnPage; | |
17 | private $rssLimit; | |
18 | private $language; | |
fcb1fba5 | 19 | |
772d8c4b | 20 | public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language) |
fcb1fba5 | 21 | { |
fcb1fba5 | 22 | $this->em = $em; |
772d8c4b JB |
23 | $this->theme = $theme; |
24 | $this->itemsOnPage = $itemsOnPage; | |
25 | $this->rssLimit = $rssLimit; | |
26 | $this->language = $language; | |
fcb1fba5 NL |
27 | } |
28 | ||
29 | public static function getSubscribedEvents() | |
30 | { | |
4094ea47 | 31 | return [ |
fcb1fba5 | 32 | FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate', |
4094ea47 | 33 | ]; |
fcb1fba5 NL |
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()); | |
772d8c4b JB |
43 | $config->setTheme($this->theme); |
44 | $config->setItemsPerPage($this->itemsOnPage); | |
45 | $config->setRssLimit($this->rssLimit); | |
46 | $config->setLanguage($this->language); | |
fcb1fba5 NL |
47 | $this->em->persist($config); |
48 | $this->em->flush(); | |
49 | } | |
50 | } |