]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/DeveloperController.php
Changed relation between API client and refresh token
[github/wallabag/wallabag.git] / src / Wallabag / CoreBundle / Controller / DeveloperController.php
CommitLineData
24152cdb
NL
1<?php
2
3namespace Wallabag\CoreBundle\Controller;
4
5use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
6use Symfony\Component\HttpFoundation\Request;
7use Symfony\Bundle\FrameworkBundle\Controller\Controller;
abc32945
NL
8use Wallabag\ApiBundle\Entity\Client;
9use Wallabag\CoreBundle\Form\Type\ClientType;
24152cdb
NL
10
11class DeveloperController extends Controller
12{
13 /**
1256f6fe
JB
14 * List all clients and link to create a new one.
15 *
24152cdb 16 * @Route("/developer", name="developer")
b6321bed
NL
17 *
18 * @return \Symfony\Component\HttpFoundation\Response
24152cdb 19 */
abc32945 20 public function indexAction()
24152cdb 21 {
9bf15f02
JB
22 $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll();
23
2ff9991a 24 return $this->render('@WallabagCore/themes/common/Developer/index.html.twig', [
9bf15f02 25 'clients' => $clients,
4094ea47 26 ]);
24152cdb
NL
27 }
28
29 /**
1256f6fe
JB
30 * Create a client (an app).
31 *
24152cdb
NL
32 * @param Request $request
33 *
9bf15f02 34 * @Route("/developer/client/create", name="developer_create_client")
b6321bed
NL
35 *
36 * @return \Symfony\Component\HttpFoundation\Response
24152cdb
NL
37 */
38 public function createClientAction(Request $request)
39 {
abc32945
NL
40 $em = $this->getDoctrine()->getManager();
41 $client = new Client();
42 $clientForm = $this->createForm(ClientType::class, $client);
43 $clientForm->handleRequest($request);
44
45 if ($clientForm->isValid()) {
4094ea47 46 $client->setAllowedGrantTypes(['token', 'authorization_code', 'password', 'refresh_token']);
abc32945
NL
47 $em->persist($client);
48 $em->flush();
49
50 $this->get('session')->getFlashBag()->add(
51 'notice',
543da3e0 52 $this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()])
abc32945
NL
53 );
54
2ff9991a 55 return $this->render('@WallabagCore/themes/common/Developer/client_parameters.html.twig', [
abc32945
NL
56 'client_id' => $client->getPublicId(),
57 'client_secret' => $client->getSecret(),
9c545fe0 58 'client_name' => $client->getName(),
4094ea47 59 ]);
abc32945 60 }
24152cdb 61
2ff9991a 62 return $this->render('@WallabagCore/themes/common/Developer/client.html.twig', [
abc32945 63 'form' => $clientForm->createView(),
4094ea47 64 ]);
24152cdb 65 }
b6321bed
NL
66
67 /**
9bf15f02
JB
68 * Remove a client.
69 *
1256f6fe 70 * @param Client $client
9bf15f02
JB
71 *
72 * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client")
73 *
74 * @return \Symfony\Component\HttpFoundation\RedirectResponse
75 */
1256f6fe 76 public function deleteClientAction(Client $client)
9bf15f02
JB
77 {
78 $em = $this->getDoctrine()->getManager();
79 $em->remove($client);
80 $em->flush();
81
82 $this->get('session')->getFlashBag()->add(
83 'notice',
543da3e0 84 $this->get('translator')->trans('flashes.developer.notice.client_deleted', ['%name%' => $client->getName()])
9bf15f02
JB
85 );
86
87 return $this->redirect($this->generateUrl('developer'));
88 }
89
90 /**
1256f6fe
JB
91 * Display developer how to use an existing app.
92 *
9bf15f02 93 * @Route("/developer/howto/first-app", name="developer_howto_firstapp")
b6321bed
NL
94 *
95 * @return \Symfony\Component\HttpFoundation\Response
96 */
abc32945 97 public function howtoFirstAppAction()
b6321bed 98 {
2ff9991a 99 return $this->render('@WallabagCore/themes/common/Developer/howto_app.html.twig');
b6321bed 100 }
24152cdb 101}