]>
Commit | Line | Data |
---|---|---|
24152cdb NL |
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; | |
abc32945 NL |
8 | use Wallabag\ApiBundle\Entity\Client; |
9 | use Wallabag\CoreBundle\Form\Type\ClientType; | |
24152cdb NL |
10 | |
11 | class DeveloperController extends Controller | |
12 | { | |
13 | /** | |
24152cdb | 14 | * @Route("/developer", name="developer") |
b6321bed NL |
15 | * |
16 | * @return \Symfony\Component\HttpFoundation\Response | |
24152cdb | 17 | */ |
abc32945 | 18 | public function indexAction() |
24152cdb | 19 | { |
9bf15f02 JB |
20 | $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll(); |
21 | ||
22 | return $this->render('WallabagCoreBundle:Developer:index.html.twig', array( | |
23 | 'clients' => $clients, | |
24 | )); | |
24152cdb NL |
25 | } |
26 | ||
27 | /** | |
28 | * @param Request $request | |
29 | * | |
9bf15f02 | 30 | * @Route("/developer/client/create", name="developer_create_client") |
b6321bed NL |
31 | * |
32 | * @return \Symfony\Component\HttpFoundation\Response | |
24152cdb NL |
33 | */ |
34 | public function createClientAction(Request $request) | |
35 | { | |
abc32945 NL |
36 | $em = $this->getDoctrine()->getManager(); |
37 | $client = new Client(); | |
38 | $clientForm = $this->createForm(ClientType::class, $client); | |
39 | $clientForm->handleRequest($request); | |
40 | ||
41 | if ($clientForm->isValid()) { | |
2c2308b7 | 42 | $client->setAllowedGrantTypes(array('token', 'authorization_code', 'password')); |
abc32945 NL |
43 | $em->persist($client); |
44 | $em->flush(); | |
45 | ||
46 | $this->get('session')->getFlashBag()->add( | |
47 | 'notice', | |
48 | 'New client created.' | |
49 | ); | |
50 | ||
51 | return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', array( | |
52 | 'client_id' => $client->getPublicId(), | |
53 | 'client_secret' => $client->getSecret(), | |
54 | )); | |
55 | } | |
24152cdb NL |
56 | |
57 | return $this->render('WallabagCoreBundle:Developer:client.html.twig', array( | |
abc32945 | 58 | 'form' => $clientForm->createView(), |
24152cdb NL |
59 | )); |
60 | } | |
b6321bed NL |
61 | |
62 | /** | |
9bf15f02 JB |
63 | * Remove a client. |
64 | * | |
65 | * @param Request $request | |
66 | * | |
67 | * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client") | |
68 | * | |
69 | * @return \Symfony\Component\HttpFoundation\RedirectResponse | |
70 | */ | |
71 | public function deleteClientAction(Request $request, Client $client) | |
72 | { | |
73 | $em = $this->getDoctrine()->getManager(); | |
74 | $em->remove($client); | |
75 | $em->flush(); | |
76 | ||
77 | $this->get('session')->getFlashBag()->add( | |
78 | 'notice', | |
79 | 'Client deleted' | |
80 | ); | |
81 | ||
82 | return $this->redirect($this->generateUrl('developer')); | |
83 | } | |
84 | ||
85 | /** | |
86 | * @Route("/developer/howto/first-app", name="developer_howto_firstapp") | |
b6321bed NL |
87 | * |
88 | * @return \Symfony\Component\HttpFoundation\Response | |
89 | */ | |
abc32945 | 90 | public function howtoFirstAppAction() |
b6321bed NL |
91 | { |
92 | return $this->render('WallabagCoreBundle:Developer:howto_app.html.twig'); | |
93 | } | |
24152cdb | 94 | } |