diff options
author | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-03-08 10:09:39 +0100 |
---|---|---|
committer | Nicolas LÅ“uillet <nicolas@loeuillet.org> | 2016-03-08 10:09:39 +0100 |
commit | 807037884f0085cd39fe4b41cacd82be14e309d9 (patch) | |
tree | a0e01ec2268faa2415e814c38549ae065e32bb7c /src/Wallabag/CoreBundle/Controller/DeveloperController.php | |
parent | 1e5a4b36ab9e50047e48f247b84733bdf9417844 (diff) | |
parent | d11eb2e461a3ea2b74e5a1c686c9fa9bbcb9e103 (diff) | |
download | wallabag-807037884f0085cd39fe4b41cacd82be14e309d9.tar.gz wallabag-807037884f0085cd39fe4b41cacd82be14e309d9.tar.zst wallabag-807037884f0085cd39fe4b41cacd82be14e309d9.zip |
Merge pull request #1675 from wallabag/v2-create-api-client
Ability to create new client for the API
Diffstat (limited to 'src/Wallabag/CoreBundle/Controller/DeveloperController.php')
-rw-r--r-- | src/Wallabag/CoreBundle/Controller/DeveloperController.php | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php new file mode 100644 index 00000000..71065534 --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/DeveloperController.php | |||
@@ -0,0 +1,100 @@ | |||
1 | <?php | ||
2 | |||
3 | namespace Wallabag\CoreBundle\Controller; | ||
4 | |||
5 | use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route; | ||
6 | use Symfony\Component\HttpFoundation\Request; | ||
7 | use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
8 | use Wallabag\ApiBundle\Entity\Client; | ||
9 | use Wallabag\CoreBundle\Form\Type\ClientType; | ||
10 | |||
11 | class DeveloperController extends Controller | ||
12 | { | ||
13 | /** | ||
14 | * List all clients and link to create a new one. | ||
15 | * | ||
16 | * @Route("/developer", name="developer") | ||
17 | * | ||
18 | * @return \Symfony\Component\HttpFoundation\Response | ||
19 | */ | ||
20 | public function indexAction() | ||
21 | { | ||
22 | $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll(); | ||
23 | |||
24 | return $this->render('WallabagCoreBundle:Developer:index.html.twig', array( | ||
25 | 'clients' => $clients, | ||
26 | )); | ||
27 | } | ||
28 | |||
29 | /** | ||
30 | * Create a client (an app). | ||
31 | * | ||
32 | * @param Request $request | ||
33 | * | ||
34 | * @Route("/developer/client/create", name="developer_create_client") | ||
35 | * | ||
36 | * @return \Symfony\Component\HttpFoundation\Response | ||
37 | */ | ||
38 | public function createClientAction(Request $request) | ||
39 | { | ||
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()) { | ||
46 | $client->setAllowedGrantTypes(array('token', 'authorization_code', 'password')); | ||
47 | $em->persist($client); | ||
48 | $em->flush(); | ||
49 | |||
50 | $this->get('session')->getFlashBag()->add( | ||
51 | 'notice', | ||
52 | 'New client created.' | ||
53 | ); | ||
54 | |||
55 | return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', array( | ||
56 | 'client_id' => $client->getPublicId(), | ||
57 | 'client_secret' => $client->getSecret(), | ||
58 | )); | ||
59 | } | ||
60 | |||
61 | return $this->render('WallabagCoreBundle:Developer:client.html.twig', array( | ||
62 | 'form' => $clientForm->createView(), | ||
63 | )); | ||
64 | } | ||
65 | |||
66 | /** | ||
67 | * Remove a client. | ||
68 | * | ||
69 | * @param Client $client | ||
70 | * | ||
71 | * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client") | ||
72 | * | ||
73 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | ||
74 | */ | ||
75 | public function deleteClientAction(Client $client) | ||
76 | { | ||
77 | $em = $this->getDoctrine()->getManager(); | ||
78 | $em->remove($client); | ||
79 | $em->flush(); | ||
80 | |||
81 | $this->get('session')->getFlashBag()->add( | ||
82 | 'notice', | ||
83 | 'Client deleted' | ||
84 | ); | ||
85 | |||
86 | return $this->redirect($this->generateUrl('developer')); | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * Display developer how to use an existing app. | ||
91 | * | ||
92 | * @Route("/developer/howto/first-app", name="developer_howto_firstapp") | ||
93 | * | ||
94 | * @return \Symfony\Component\HttpFoundation\Response | ||
95 | */ | ||
96 | public function howtoFirstAppAction() | ||
97 | { | ||
98 | return $this->render('WallabagCoreBundle:Developer:howto_app.html.twig'); | ||
99 | } | ||
100 | } | ||