diff options
author | Thomas Citharel <tcit@tcit.fr> | 2017-05-31 09:31:18 +0200 |
---|---|---|
committer | Thomas Citharel <tcit@tcit.fr> | 2017-06-23 10:08:54 +0200 |
commit | bf6c0346d8d35a719dd1bff1cb4d573d422f99ff (patch) | |
tree | 04fb80e20ad1cffacb72357a632a9afe2ec058cb /src/Wallabag/FederationBundle/EventListener | |
parent | d6d3f4ec3698effd1d4b063e295341791bdcf7d7 (diff) | |
download | wallabag-bf6c0346d8d35a719dd1bff1cb4d573d422f99ff.tar.gz wallabag-bf6c0346d8d35a719dd1bff1cb4d573d422f99ff.tar.zst wallabag-bf6c0346d8d35a719dd1bff1cb4d573d422f99ff.zip |
WIPfederation
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
Diffstat (limited to 'src/Wallabag/FederationBundle/EventListener')
-rw-r--r-- | src/Wallabag/FederationBundle/EventListener/CreateAccountListener.php | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/src/Wallabag/FederationBundle/EventListener/CreateAccountListener.php b/src/Wallabag/FederationBundle/EventListener/CreateAccountListener.php new file mode 100644 index 00000000..92626b15 --- /dev/null +++ b/src/Wallabag/FederationBundle/EventListener/CreateAccountListener.php | |||
@@ -0,0 +1,54 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\FederationBundle\EventListener; | ||
4 | |||
5 | use Doctrine\ORM\EntityManager; | ||
6 | use FOS\UserBundle\Event\UserEvent; | ||
7 | use FOS\UserBundle\FOSUserEvents; | ||
8 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; | ||
9 | use Symfony\Component\EventDispatcher\EventSubscriberInterface; | ||
10 | use Wallabag\CoreBundle\Entity\Config; | ||
11 | use Wallabag\FederationBundle\Entity\Account; | ||
12 | |||
13 | /** | ||
14 | * This listener will create the associated configuration when a user register. | ||
15 | * This configuration will be created right after the registration (no matter if it needs an email validation). | ||
16 | */ | ||
17 | class CreateAccountListener implements EventSubscriberInterface | ||
18 | { | ||
19 | private $em; | ||
20 | private $domainName; | ||
21 | |||
22 | public function __construct(EntityManager $em, $domainName) | ||
23 | { | ||
24 | $this->em = $em; | ||
25 | $this->domainName = $domainName; | ||
26 | } | ||
27 | |||
28 | public static function getSubscribedEvents() | ||
29 | { | ||
30 | return [ | ||
31 | // when a user register using the normal form | ||
32 | FOSUserEvents::REGISTRATION_COMPLETED => 'createAccount', | ||
33 | // when we manually create a user using the command line | ||
34 | // OR when we create it from the config UI | ||
35 | FOSUserEvents::USER_CREATED => 'createAccount', | ||
36 | ]; | ||
37 | } | ||
38 | |||
39 | public function createAccount(UserEvent $event) | ||
40 | { | ||
41 | $user = $event->getUser(); | ||
42 | $account = new Account(); | ||
43 | $account->setUser($user) | ||
44 | ->setUsername($user->getUsername()) | ||
45 | ->setServer($this->domainName); | ||
46 | |||
47 | $this->em->persist($account); | ||
48 | |||
49 | $user->setAccount($account); | ||
50 | |||
51 | $this->em->persist($user); | ||
52 | $this->em->flush(); | ||
53 | } | ||
54 | } | ||