]>
Commit | Line | Data |
---|---|---|
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 | * @Route("/developer", name="developer") | |
15 | * | |
16 | * @return \Symfony\Component\HttpFoundation\Response | |
17 | */ | |
18 | public function indexAction() | |
19 | { | |
20 | $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll(); | |
21 | ||
22 | return $this->render('WallabagCoreBundle:Developer:index.html.twig', array( | |
23 | 'clients' => $clients, | |
24 | )); | |
25 | } | |
26 | ||
27 | /** | |
28 | * @param Request $request | |
29 | * | |
30 | * @Route("/developer/client/create", name="developer_create_client") | |
31 | * | |
32 | * @return \Symfony\Component\HttpFoundation\Response | |
33 | */ | |
34 | public function createClientAction(Request $request) | |
35 | { | |
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()) { | |
42 | $client->setAllowedGrantTypes(array('token', 'authorization_code', 'password')); | |
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 | } | |
56 | ||
57 | return $this->render('WallabagCoreBundle:Developer:client.html.twig', array( | |
58 | 'form' => $clientForm->createView(), | |
59 | )); | |
60 | } | |
61 | ||
62 | /** | |
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") | |
87 | * | |
88 | * @return \Symfony\Component\HttpFoundation\Response | |
89 | */ | |
90 | public function howtoFirstAppAction() | |
91 | { | |
92 | return $this->render('WallabagCoreBundle:Developer:howto_app.html.twig'); | |
93 | } | |
94 | } |