3 namespace Wallabag\ApiBundle\Controller
;
5 use Symfony\Bundle\FrameworkBundle\Controller\Controller
;
6 use Symfony\Component\HttpFoundation\Request
;
7 use Symfony\Component\Routing\Annotation\Route
;
8 use Wallabag\ApiBundle\Entity\Client
;
9 use Wallabag\ApiBundle\Form\Type\ClientType
;
11 class DeveloperController
extends Controller
14 * List all clients and link to create a new one.
16 * @Route("/developer", name="developer")
18 * @return \Symfony\Component\HttpFoundation\Response
20 public function indexAction()
22 $clients = $this->getDoctrine()->getRepository('WallabagApiBundle:Client')->findByUser($this->getUser()->getId());
24 return $this->render('@WallabagCore/themes/common/Developer/index.html.twig', [
25 'clients' => $clients,
30 * Create a client (an app).
32 * @Route("/developer/client/create", name="developer_create_client")
34 * @return \Symfony\Component\HttpFoundation\Response
36 public function createClientAction(Request
$request)
38 $em = $this->getDoctrine()->getManager();
39 $client = new Client($this->getUser());
40 $clientForm = $this->createForm(ClientType
::class, $client);
41 $clientForm->handleRequest($request);
43 if ($clientForm->isSubmitted() && $clientForm->isValid()) {
44 $client->setAllowedGrantTypes(['token', 'authorization_code', 'password', 'refresh_token']);
45 $em->persist($client);
48 $this->get('session')->getFlashBag()->add(
50 $this->get('translator')->trans('flashes.developer.notice.client_created', ['%name%' => $client->getName()])
53 return $this->render('@WallabagCore/themes/common/Developer/client_parameters.html.twig', [
54 'client_id' => $client->getPublicId(),
55 'client_secret' => $client->getSecret(),
56 'client_name' => $client->getName(),
60 return $this->render('@WallabagCore/themes/common/Developer/client.html.twig', [
61 'form' => $clientForm->createView(),
68 * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client")
70 * @return \Symfony\Component\HttpFoundation\RedirectResponse
72 public function deleteClientAction(Client
$client)
74 if (null === $this->getUser() || $client->getUser()->getId() !== $this->getUser()->getId()) {
75 throw $this->createAccessDeniedException('You can not access this client.');
78 $em = $this->getDoctrine()->getManager();
82 $this->get('session')->getFlashBag()->add(
84 $this->get('translator')->trans('flashes.developer.notice.client_deleted', ['%name%' => $client->getName()])
87 return $this->redirect($this->generateUrl('developer'));
91 * Display developer how to use an existing app.
93 * @Route("/developer/howto/first-app", name="developer_howto_firstapp")
95 * @return \Symfony\Component\HttpFoundation\Response
97 public function howtoFirstAppAction()
99 return $this->render('@WallabagCore/themes/common/Developer/howto_app.html.twig');