diff options
Diffstat (limited to 'src/Wallabag/FederationBundle/Controller/InboxController.php')
-rw-r--r-- | src/Wallabag/FederationBundle/Controller/InboxController.php | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/src/Wallabag/FederationBundle/Controller/InboxController.php b/src/Wallabag/FederationBundle/Controller/InboxController.php new file mode 100644 index 00000000..99cfeadf --- /dev/null +++ b/src/Wallabag/FederationBundle/Controller/InboxController.php | |||
@@ -0,0 +1,43 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\FederationBundle\Controller; | ||
4 | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\ParamConverter; | ||
6 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
8 | use Symfony\Component\HttpFoundation\Request; | ||
9 | use Symfony\Component\HttpFoundation\Response; | ||
10 | use Wallabag\FederationBundle\Entity\Account; | ||
11 | use Wallabag\FederationBundle\Entity\Instance; | ||
12 | use Wallabag\FederationBundle\Federation\CloudId; | ||
13 | |||
14 | class InboxController extends Controller | ||
15 | { | ||
16 | /** | ||
17 | * @Route("/profile/inbox", name="user-inbox") | ||
18 | * | ||
19 | * @param Request $request | ||
20 | * @return Response | ||
21 | */ | ||
22 | public function userInboxAction(Request $request) | ||
23 | { | ||
24 | $em = $this->getDoctrine()->getManager(); | ||
25 | $response = new Response(); | ||
26 | |||
27 | if ($activity = json_decode($request->getContent())) { | ||
28 | if ($activity->type === 'Follow' && isset($activity->actor->id)) { | ||
29 | $cloudId = new CloudId($activity->actor->id); | ||
30 | $account = new Account(); | ||
31 | $account->setServer($cloudId->getRemote()) | ||
32 | ->setUsername($cloudId->getUser()); | ||
33 | $em->persist($account); | ||
34 | $em->flush(); | ||
35 | |||
36 | $response->setStatusCode(201); | ||
37 | } else { | ||
38 | $response->setStatusCode(400); | ||
39 | } | ||
40 | } | ||
41 | return $response; | ||
42 | } | ||
43 | } | ||