]> git.immae.eu Git - github/wallabag/wallabag.git/blame - src/Wallabag/CoreBundle/Controller/DeveloperController.php
Replace slider with select
[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
24 return $this->render('WallabagCoreBundle:Developer:index.html.twig', array(
25 'clients' => $clients,
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()) {
6432b927 46 $client->setAllowedGrantTypes(array('token', 'authorization_code', 'password', 'refresh_token'));
abc32945
NL
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 }
24152cdb
NL
60
61 return $this->render('WallabagCoreBundle:Developer:client.html.twig', array(
abc32945 62 'form' => $clientForm->createView(),
24152cdb
NL
63 ));
64 }
b6321bed
NL
65
66 /**
9bf15f02
JB
67 * Remove a client.
68 *
1256f6fe 69 * @param Client $client
9bf15f02
JB
70 *
71 * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client")
72 *
73 * @return \Symfony\Component\HttpFoundation\RedirectResponse
74 */
1256f6fe 75 public function deleteClientAction(Client $client)
9bf15f02
JB
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 /**
1256f6fe
JB
90 * Display developer how to use an existing app.
91 *
9bf15f02 92 * @Route("/developer/howto/first-app", name="developer_howto_firstapp")
b6321bed
NL
93 *
94 * @return \Symfony\Component\HttpFoundation\Response
95 */
abc32945 96 public function howtoFirstAppAction()
b6321bed
NL
97 {
98 return $this->render('WallabagCoreBundle:Developer:howto_app.html.twig');
99 }
24152cdb 100}