aboutsummaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-10-01 15:51:37 +0200
committerGitHub <noreply@github.com>2016-10-01 15:51:37 +0200
commitdb5541e7a1e7131d62b4df23fa6eadd0c542b256 (patch)
treec5c71df873a9aa9350660e225f046a448274868f /src
parent114c55c0a6eade2ba6c53fe25f61cc58cca91620 (diff)
parentfb7354c4a430f4f4916a1247aa1b1bf564ead0da (diff)
downloadwallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.tar.gz
wallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.tar.zst
wallabag-db5541e7a1e7131d62b4df23fa6eadd0c542b256.zip
Merge pull request #2320 from wallabag/user-config
Create user config in one place.
Diffstat (limited to 'src')
-rw-r--r--src/Wallabag/CoreBundle/Command/InstallCommand.php13
-rw-r--r--src/Wallabag/CoreBundle/Controller/ConfigController.php18
-rw-r--r--src/Wallabag/CoreBundle/Resources/config/services.yml11
-rw-r--r--src/Wallabag/UserBundle/EventListener/CreateConfigListener.php (renamed from src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php)24
-rw-r--r--src/Wallabag/UserBundle/Resources/config/services.yml12
-rw-r--r--src/Wallabag/UserBundle/Resources/views/Registration/check_email.html.twig (renamed from src/Wallabag/UserBundle/Resources/views/Registration/checkEmail.html.twig)0
6 files changed, 42 insertions, 36 deletions
diff --git a/src/Wallabag/CoreBundle/Command/InstallCommand.php b/src/Wallabag/CoreBundle/Command/InstallCommand.php
index 3873d2d3..cc7c2c94 100644
--- a/src/Wallabag/CoreBundle/Command/InstallCommand.php
+++ b/src/Wallabag/CoreBundle/Command/InstallCommand.php
@@ -2,6 +2,8 @@
2 2
3namespace Wallabag\CoreBundle\Command; 3namespace Wallabag\CoreBundle\Command;
4 4
5use FOS\UserBundle\Event\UserEvent;
6use FOS\UserBundle\FOSUserEvents;
5use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; 7use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
6use Symfony\Component\Console\Helper\Table; 8use Symfony\Component\Console\Helper\Table;
7use Symfony\Component\Console\Input\ArrayInput; 9use Symfony\Component\Console\Input\ArrayInput;
@@ -236,14 +238,9 @@ class InstallCommand extends ContainerAwareCommand
236 238
237 $em->persist($user); 239 $em->persist($user);
238 240
239 $config = new Config($user); 241 // dispatch a created event so the associated config will be created
240 $config->setTheme($this->getContainer()->getParameter('wallabag_core.theme')); 242 $event = new UserEvent($user);
241 $config->setItemsPerPage($this->getContainer()->getParameter('wallabag_core.items_on_page')); 243 $this->getContainer()->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
242 $config->setRssLimit($this->getContainer()->getParameter('wallabag_core.rss_limit'));
243 $config->setReadingSpeed($this->getContainer()->getParameter('wallabag_core.reading_speed'));
244 $config->setLanguage($this->getContainer()->getParameter('wallabag_core.language'));
245
246 $em->persist($config);
247 244
248 $this->defaultOutput->writeln(''); 245 $this->defaultOutput->writeln('');
249 246
diff --git a/src/Wallabag/CoreBundle/Controller/ConfigController.php b/src/Wallabag/CoreBundle/Controller/ConfigController.php
index 4f75511b..75a9af0b 100644
--- a/src/Wallabag/CoreBundle/Controller/ConfigController.php
+++ b/src/Wallabag/CoreBundle/Controller/ConfigController.php
@@ -2,6 +2,8 @@
2 2
3namespace Wallabag\CoreBundle\Controller; 3namespace Wallabag\CoreBundle\Controller;
4 4
5use FOS\UserBundle\Event\UserEvent;
6use FOS\UserBundle\FOSUserEvents;
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; 7use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Bundle\FrameworkBundle\Controller\Controller; 8use Symfony\Bundle\FrameworkBundle\Controller\Controller;
7use Symfony\Component\HttpFoundation\JsonResponse; 9use Symfony\Component\HttpFoundation\JsonResponse;
@@ -133,18 +135,11 @@ class ConfigController extends Controller
133 $newUserForm->handleRequest($request); 135 $newUserForm->handleRequest($request);
134 136
135 if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) { 137 if ($newUserForm->isValid() && $this->get('security.authorization_checker')->isGranted('ROLE_SUPER_ADMIN')) {
136 $userManager->updateUser($newUser, true); 138 $userManager->updateUser($newUser);
137 139
138 $config = new Config($newUser); 140 // dispatch a created event so the associated config will be created
139 $config->setTheme($this->getParameter('wallabag_core.theme')); 141 $event = new UserEvent($newUser, $request);
140 $config->setItemsPerPage($this->getParameter('wallabag_core.items_on_page')); 142 $this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
141 $config->setRssLimit($this->getParameter('wallabag_core.rss_limit'));
142 $config->setLanguage($this->getParameter('wallabag_core.language'));
143 $config->setReadingSpeed($this->getParameter('wallabag_core.reading_speed'));
144
145 $em->persist($config);
146
147 $em->flush();
148 143
149 $this->get('session')->getFlashBag()->add( 144 $this->get('session')->getFlashBag()->add(
150 'notice', 145 'notice',
@@ -238,6 +233,7 @@ class ConfigController extends Controller
238 ->getRepository('WallabagCoreBundle:Config') 233 ->getRepository('WallabagCoreBundle:Config')
239 ->findOneByUser($this->getUser()); 234 ->findOneByUser($this->getUser());
240 235
236 // should NEVER HAPPEN ...
241 if (!$config) { 237 if (!$config) {
242 $config = new Config($this->getUser()); 238 $config = new Config($this->getUser());
243 } 239 }
diff --git a/src/Wallabag/CoreBundle/Resources/config/services.yml b/src/Wallabag/CoreBundle/Resources/config/services.yml
index 23e6d3ca..5a727ec5 100644
--- a/src/Wallabag/CoreBundle/Resources/config/services.yml
+++ b/src/Wallabag/CoreBundle/Resources/config/services.yml
@@ -88,17 +88,6 @@ services:
88 arguments: 88 arguments:
89 - WallabagCoreBundle:Tag 89 - WallabagCoreBundle:Tag
90 90
91 wallabag_core.registration_confirmed:
92 class: Wallabag\CoreBundle\EventListener\RegistrationConfirmedListener
93 arguments:
94 - "@doctrine.orm.entity_manager"
95 - "%wallabag_core.theme%"
96 - "%wallabag_core.items_on_page%"
97 - "%wallabag_core.rss_limit%"
98 - "%wallabag_core.language%"
99 tags:
100 - { name: kernel.event_subscriber }
101
102 wallabag_core.helper.entries_export: 91 wallabag_core.helper.entries_export:
103 class: Wallabag\CoreBundle\Helper\EntriesExport 92 class: Wallabag\CoreBundle\Helper\EntriesExport
104 arguments: 93 arguments:
diff --git a/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
index 10586126..15f4ac3d 100644
--- a/src/Wallabag/CoreBundle/EventListener/RegistrationConfirmedListener.php
+++ b/src/Wallabag/UserBundle/EventListener/CreateConfigListener.php
@@ -1,39 +1,49 @@
1<?php 1<?php
2 2
3namespace Wallabag\CoreBundle\EventListener; 3namespace Wallabag\UserBundle\EventListener;
4 4
5use Doctrine\ORM\EntityManager; 5use Doctrine\ORM\EntityManager;
6use FOS\UserBundle\Event\FilterUserResponseEvent; 6use FOS\UserBundle\Event\UserEvent;
7use FOS\UserBundle\FOSUserEvents; 7use FOS\UserBundle\FOSUserEvents;
8use Symfony\Component\EventDispatcher\EventDispatcherInterface; 8use Symfony\Component\EventDispatcher\EventDispatcherInterface;
9use Symfony\Component\EventDispatcher\EventSubscriberInterface; 9use Symfony\Component\EventDispatcher\EventSubscriberInterface;
10use Wallabag\CoreBundle\Entity\Config; 10use Wallabag\CoreBundle\Entity\Config;
11 11
12class RegistrationConfirmedListener implements EventSubscriberInterface 12/**
13 * This listener will create the associated configuration when a user register.
14 * This configuration will be created right after the registration (no matter if it needs an email validation).
15 */
16class CreateConfigListener implements EventSubscriberInterface
13{ 17{
14 private $em; 18 private $em;
15 private $theme; 19 private $theme;
16 private $itemsOnPage; 20 private $itemsOnPage;
17 private $rssLimit; 21 private $rssLimit;
18 private $language; 22 private $language;
23 private $readingSpeed;
19 24
20 public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language) 25 public function __construct(EntityManager $em, $theme, $itemsOnPage, $rssLimit, $language, $readingSpeed)
21 { 26 {
22 $this->em = $em; 27 $this->em = $em;
23 $this->theme = $theme; 28 $this->theme = $theme;
24 $this->itemsOnPage = $itemsOnPage; 29 $this->itemsOnPage = $itemsOnPage;
25 $this->rssLimit = $rssLimit; 30 $this->rssLimit = $rssLimit;
26 $this->language = $language; 31 $this->language = $language;
32 $this->readingSpeed = $readingSpeed;
27 } 33 }
28 34
29 public static function getSubscribedEvents() 35 public static function getSubscribedEvents()
30 { 36 {
31 return [ 37 return [
32 FOSUserEvents::REGISTRATION_CONFIRMED => 'authenticate', 38 // when a user register using the normal form
39 FOSUserEvents::REGISTRATION_COMPLETED => 'createConfig',
40 // when we manually create a user using the command line
41 // OR when we create it from the config UI
42 FOSUserEvents::USER_CREATED => 'createConfig',
33 ]; 43 ];
34 } 44 }
35 45
36 public function authenticate(FilterUserResponseEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null) 46 public function createConfig(UserEvent $event, $eventName = null, EventDispatcherInterface $eventDispatcher = null)
37 { 47 {
38 if (!$event->getUser()->isEnabled()) { 48 if (!$event->getUser()->isEnabled()) {
39 return; 49 return;
@@ -44,6 +54,8 @@ class RegistrationConfirmedListener implements EventSubscriberInterface
44 $config->setItemsPerPage($this->itemsOnPage); 54 $config->setItemsPerPage($this->itemsOnPage);
45 $config->setRssLimit($this->rssLimit); 55 $config->setRssLimit($this->rssLimit);
46 $config->setLanguage($this->language); 56 $config->setLanguage($this->language);
57 $config->setReadingSpeed($this->readingSpeed);
58
47 $this->em->persist($config); 59 $this->em->persist($config);
48 $this->em->flush(); 60 $this->em->flush();
49 } 61 }
diff --git a/src/Wallabag/UserBundle/Resources/config/services.yml b/src/Wallabag/UserBundle/Resources/config/services.yml
index 05830555..eb9c8e67 100644
--- a/src/Wallabag/UserBundle/Resources/config/services.yml
+++ b/src/Wallabag/UserBundle/Resources/config/services.yml
@@ -20,3 +20,15 @@ services:
20 factory: [ "@doctrine.orm.default_entity_manager", getRepository ] 20 factory: [ "@doctrine.orm.default_entity_manager", getRepository ]
21 arguments: 21 arguments:
22 - WallabagUserBundle:User 22 - WallabagUserBundle:User
23
24 wallabag_user.create_config:
25 class: Wallabag\UserBundle\EventListener\CreateConfigListener
26 arguments:
27 - "@doctrine.orm.entity_manager"
28 - "%wallabag_core.theme%"
29 - "%wallabag_core.items_on_page%"
30 - "%wallabag_core.rss_limit%"
31 - "%wallabag_core.language%"
32 - "%wallabag_core.reading_speed%"
33 tags:
34 - { name: kernel.event_subscriber }
diff --git a/src/Wallabag/UserBundle/Resources/views/Registration/checkEmail.html.twig b/src/Wallabag/UserBundle/Resources/views/Registration/check_email.html.twig
index 50937276..50937276 100644
--- a/src/Wallabag/UserBundle/Resources/views/Registration/checkEmail.html.twig
+++ b/src/Wallabag/UserBundle/Resources/views/Registration/check_email.html.twig