diff --git a/src/Wallabag/CoreBundle/Controller/DeveloperController.php b/src/Wallabag/CoreBundle/Controller/DeveloperController.php new file mode 100644 index 000000000..71065534e --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/DeveloperController.php @@ -0,0 +1,100 @@ +getDoctrine()->getRepository('WallabagApiBundle:Client')->findAll(); + + return $this->render('WallabagCoreBundle:Developer:index.html.twig', array( + 'clients' => $clients, + )); + } + + /** + * Create a client (an app). + * + * @param Request $request + * + * @Route("/developer/client/create", name="developer_create_client") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function createClientAction(Request $request) + { + $em = $this->getDoctrine()->getManager(); + $client = new Client(); + $clientForm = $this->createForm(ClientType::class, $client); + $clientForm->handleRequest($request); + + if ($clientForm->isValid()) { + $client->setAllowedGrantTypes(array('token', 'authorization_code', 'password')); + $em->persist($client); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'New client created.' + ); + + return $this->render('WallabagCoreBundle:Developer:client_parameters.html.twig', array( + 'client_id' => $client->getPublicId(), + 'client_secret' => $client->getSecret(), + )); + } + + return $this->render('WallabagCoreBundle:Developer:client.html.twig', array( + 'form' => $clientForm->createView(), + )); + } + + /** + * Remove a client. + * + * @param Client $client + * + * @Route("/developer/client/delete/{id}", requirements={"id" = "\d+"}, name="developer_delete_client") + * + * @return \Symfony\Component\HttpFoundation\RedirectResponse + */ + public function deleteClientAction(Client $client) + { + $em = $this->getDoctrine()->getManager(); + $em->remove($client); + $em->flush(); + + $this->get('session')->getFlashBag()->add( + 'notice', + 'Client deleted' + ); + + return $this->redirect($this->generateUrl('developer')); + } + + /** + * Display developer how to use an existing app. + * + * @Route("/developer/howto/first-app", name="developer_howto_firstapp") + * + * @return \Symfony\Component\HttpFoundation\Response + */ + public function howtoFirstAppAction() + { + return $this->render('WallabagCoreBundle:Developer:howto_app.html.twig'); + } +} diff --git a/src/Wallabag/CoreBundle/Form/Type/ClientType.php b/src/Wallabag/CoreBundle/Form/Type/ClientType.php new file mode 100644 index 000000000..dd9347150 --- /dev/null +++ b/src/Wallabag/CoreBundle/Form/Type/ClientType.php @@ -0,0 +1,44 @@ +add('redirect_uris', UrlType::class, array('required' => true, 'label' => 'Redirect URIs')) + ->add('save', SubmitType::class, array('label' => 'Create a new client')) + ; + + $builder->get('redirect_uris') + ->addModelTransformer(new CallbackTransformer( + function ($originalUri) { + return $originalUri; + }, + function ($submittedUri) { + return array($submittedUri); + } + )) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults(array( + 'data_class' => 'Wallabag\ApiBundle\Entity\Client', + )); + } + + public function getBlockPrefix() + { + return 'client'; + } +} diff --git a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml index 6c6caa24d..b809f1ab8 100644 --- a/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml +++ b/src/Wallabag/CoreBundle/Resources/translations/messages.fr.yml @@ -242,3 +242,36 @@ If you need some help, we are here for you.: "Parce que vous avez peut-être bes On GitHub: "Sur GitHub" By email: "Par email" On Gitter: "Sur Gitter" + +# developer +Developer: Développeur +Welcome to the wallabag API: "Bienvenue sur l'API de wallabag" +How to create my first application: "Comment créer votre première application" +View full API documentation: "Voir la documentation complète de l'API" +Clients: "Clients" +Create a new client: "Créer une nouveau client" +Existing clients: "Les clients existants" +Client ID: "ID Client" +Client secret: "Clé secrète" +Redirect URIs: "URLs de redirection" +Grant type allowed: "Type de privilège accordé" +You have the ability to remove this client. This action is IRREVERSIBLE !: "Vous avez la possibilité de supprimer un client. Cette action est IRREVERSIBLE !" +If you remove it, every app configured with that client won't be able to auth on your wallabag.: "Si vous supprimez un client, toutes les applications qui l'utilisaient ne fonctionneront plus avec votre compte wallabag." +Remove this client: "Supprimer ce client" +New client: "Nouveau client" +You are about to create a new client. Please fill the field below for the redirect URI of your application.: "Vous allez créer un nouveau client. Merci de remplir l'url de redirection vers votre application." +Back: "Retour" +Client parameters: "Les paramètres de votre client" +New client created.: "Nouveau client créé." +Here are your client parameters.: "Voilà les paramètres de votre client" +Read the howto "Create my first application": "Lire \"comment créer ma première application\"" +Client deleted: "Client supprimé" +No client yet.: "Aucun client pour le moment" +"The following commands make use of the HTTPie library. Make sure it is installed on your system before using it.": "Les commandes suivantes utilisent la librarie HTTPie. Assurez-vous qu'elle soit installée avant de l'utiliser." +You need a token to communicate between your 3rd application and wallabag API.: "Vous avez besoin d'un token pour échanger entre votre application et l'API de wallabag." +"To create this token, you need to create a new client.": "Pour créer un token, vous devez créer un nouveau client." +Now, create your token (replace client_id, client_secret, username and password with the good values):: "Maintenant créez votre token (remplacer client_id, client_secret, username et password avec les bonnes valeurs):" +The API will return a response like this:: "L'API vous retournera une réponse comme ça:" +The access_token is useful to do a call to the API endpoint. For example:: "L'access_token doit être utilisé pour faire un appel à l'API. Par exemple :" +This call will return all the entries for your user.: "Cet appel va retourner tous les articles de l'utilisateur." +"If you want to see all the API endpoints, you can have a look to our API documentation.": "Si vous voulez toutes les méthodes de l'API, jetez un oeil à la documentation de l'API." diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client.html.twig new file mode 100644 index 000000000..c9ce6d087 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client.html.twig @@ -0,0 +1,31 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}New client{% endtrans %}{% endblock %} + +{% block content %} +
+
+
+ +
+

{% trans %}You are about to create a new client. Please fill the field below for the redirect URI of your application.{% endtrans %}

+ {{ form_start(form) }} + {{ form_errors(form) }} + +
+ {{ form_label(form.redirect_uris) }} + {{ form_errors(form.redirect_uris) }} + {{ form_widget(form.redirect_uris) }} +
+ + {% trans %}Back{% endtrans %} + {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + + {{ form_rest(form) }} +
+ +
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig new file mode 100644 index 000000000..a214dfd0b --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/client_parameters.html.twig @@ -0,0 +1,22 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}Client parameters{% endtrans %}{% endblock %} + +{% block content %} +
+
+
+
+

{% trans %}Here are your client parameters.{% endtrans %}

+
    +
  • {% trans %}Client ID{% endtrans %}:
    {{ client_id }}
  • +
  • {% trans %}Client secret{% endtrans %}:
    {{ client_secret }}
  • +
+ + {% trans %}Back{% endtrans %} + {% trans %}Read the howto "Create my first application"{% endtrans %} +
+
+
+
+{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig new file mode 100644 index 000000000..382e63112 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/howto_app.html.twig @@ -0,0 +1,63 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}How to create my first application{% endtrans %}{% endblock %} + +{% block css %} + {{ parent() }} + +{% endblock %} + +{% block content %} +
+
+
+ +
+

{% trans %}The following commands make use of the HTTPie library. Make sure it is installed on your system before using it.{% endtrans %}

+

{% trans %}You need a token to communicate between your 3rd application and wallabag API.{% endtrans %}

+

{% trans with {'%link%': path('developer_create_client')} %}To create this token, you need to create a new client.{% endtrans %}

+

{% trans %}Now, create your token (replace client_id, client_secret, username and password with the good values):{% endtrans %}

+

+

http POST http://v2.wallabag.org/oauth/v2/token \
+    grant_type=password \
+    client_id=12_5um6nz50ceg4088c0840wwc0kgg44g00kk84og044ggkscso0k \
+    client_secret=3qd12zpeaxes8cwg8c0404g888co4wo8kc4gcw0occww8cgw4k \
+    username=yourUsername \
+    password=yourPassw0rd
+

+

{% trans %}The API will return a response like this:{% endtrans %}

+

+

HTTP/1.1 200 OK
+Cache-Control: no-store, private
+Connection: close
+Content-Type: application/json
+Date: Tue, 06 Oct 2015 18:24:03 GMT
+Host: localhost:8000
+Pragma: no-cache
+X-Debug-Token: be00a1
+X-Debug-Token-Link: /profiler/be00a1
+X-Powered-By: PHP/5.5.9-1ubuntu4.13
+{
+    "access_token": "ZWFjNjA3ZWMwYWVmYzRkYTBlMmQ3NTllYmVhOGJiZDE0ZTg1NjE4MjczOTVlNzM0ZTRlMWQ0MmRlMmYwNTk5Mw",
+    "expires_in": 3600,
+    "refresh_token": "ODBjODU1NWUwNmUzZTBkNDQ5YWVlZTVlMjQ2Y2I0OWM2NTM1ZGM2M2Y3MDhjMTViM2U2MzYxYzRkMDk5ODRlZg",
+    "scope": null,
+    "token_type": "bearer"
+}
+

+

{% trans %}The access_token is useful to do a call to the API endpoint. For example:{% endtrans %}

+

+

http GET http://v2.wallabag.org/api/entries.json \
+    "Authorization:Bearer ZWFjNjA3ZWMwYWVmYzRkYTBlMmQ3NTllYmVhOGJiZDE0ZTg1NjE4MjczOTVlNzM0ZTRlMWQ0MmRlMmYwNTk5Mw"
+

+

{% trans %}This call will return all the entries for your user.{% endtrans %}

+

{% trans with {'%link%': path('nelmio_api_doc_index')} %}If you want to see all the API endpoints, you can have a look to our API documentation.{% endtrans %}

+

{% trans %}Back{% endtrans %}

+
+ +
+
+
+ + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig new file mode 100644 index 000000000..2e7dbcab7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/Developer/index.html.twig @@ -0,0 +1,68 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}Developer{% endtrans %}{% endblock %} + +{% block content %} +
+
+
+ +
+

{% trans %}Welcome to the wallabag API{% endtrans %}

+ +

{% trans %}Documentation{% endtrans %}

+ + + +

{% trans %}Clients{% endtrans %}

+ + +

{% trans %}Existing clients{% endtrans %}

+ {% if clients %} +
    + {% for client in clients %} +
  • +
    #{{ client.id }}
    +
    + + + + + + + + + + + + + + + + + +
    {% trans %}Client ID{% endtrans %}{{ client.id }}_{{ client.randomId }}
    {% trans %}Client secret{% endtrans %}{{ client.secret }}
    {% trans %}Redirect URIs{% endtrans %}{{ client.redirectUris|json_encode() }}
    {% trans %}Grant type allowed{% endtrans %}{{ client.allowedGrantTypes|json_encode() }}
    +

    + {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}
    + {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}
    + {% trans %}Remove this client{% endtrans %} +

    +
    +
  • + {% endfor %} +
+ {% else %} + {% trans %}No client yet.{% endtrans %} + {% endif %} +
+ +
+
+
+ +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig index 84604762d..7f0980660 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/baggy/layout.html.twig @@ -56,6 +56,7 @@ {% endif %}
  • {% trans %}import{% endtrans %}
  • {% trans %}howto{% endtrans %}
  • +
  • {% trans %}Developer{% endtrans %}
  • {% trans %}about{% endtrans %}
  • {% trans %}logout{% endtrans %}
  • diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client.html.twig new file mode 100644 index 000000000..c9ce6d087 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client.html.twig @@ -0,0 +1,31 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}New client{% endtrans %}{% endblock %} + +{% block content %} +
    +
    +
    + +
    +

    {% trans %}You are about to create a new client. Please fill the field below for the redirect URI of your application.{% endtrans %}

    + {{ form_start(form) }} + {{ form_errors(form) }} + +
    + {{ form_label(form.redirect_uris) }} + {{ form_errors(form.redirect_uris) }} + {{ form_widget(form.redirect_uris) }} +
    + + {% trans %}Back{% endtrans %} + {{ form_widget(form.save, {'attr': {'class': 'btn waves-effect waves-light'}}) }} + + {{ form_rest(form) }} +
    + +
    +
    +
    + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig new file mode 100644 index 000000000..a214dfd0b --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/client_parameters.html.twig @@ -0,0 +1,22 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}Client parameters{% endtrans %}{% endblock %} + +{% block content %} +
    +
    +
    +
    +

    {% trans %}Here are your client parameters.{% endtrans %}

    +
      +
    • {% trans %}Client ID{% endtrans %}:
      {{ client_id }}
    • +
    • {% trans %}Client secret{% endtrans %}:
      {{ client_secret }}
    • +
    + + {% trans %}Back{% endtrans %} + {% trans %}Read the howto "Create my first application"{% endtrans %} +
    +
    +
    +
    +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig new file mode 100644 index 000000000..382e63112 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/howto_app.html.twig @@ -0,0 +1,63 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}How to create my first application{% endtrans %}{% endblock %} + +{% block css %} + {{ parent() }} + +{% endblock %} + +{% block content %} +
    +
    +
    + +
    +

    {% trans %}The following commands make use of the HTTPie library. Make sure it is installed on your system before using it.{% endtrans %}

    +

    {% trans %}You need a token to communicate between your 3rd application and wallabag API.{% endtrans %}

    +

    {% trans with {'%link%': path('developer_create_client')} %}To create this token, you need to create a new client.{% endtrans %}

    +

    {% trans %}Now, create your token (replace client_id, client_secret, username and password with the good values):{% endtrans %}

    +

    +

    http POST http://v2.wallabag.org/oauth/v2/token \
    +    grant_type=password \
    +    client_id=12_5um6nz50ceg4088c0840wwc0kgg44g00kk84og044ggkscso0k \
    +    client_secret=3qd12zpeaxes8cwg8c0404g888co4wo8kc4gcw0occww8cgw4k \
    +    username=yourUsername \
    +    password=yourPassw0rd
    +

    +

    {% trans %}The API will return a response like this:{% endtrans %}

    +

    +

    HTTP/1.1 200 OK
    +Cache-Control: no-store, private
    +Connection: close
    +Content-Type: application/json
    +Date: Tue, 06 Oct 2015 18:24:03 GMT
    +Host: localhost:8000
    +Pragma: no-cache
    +X-Debug-Token: be00a1
    +X-Debug-Token-Link: /profiler/be00a1
    +X-Powered-By: PHP/5.5.9-1ubuntu4.13
    +{
    +    "access_token": "ZWFjNjA3ZWMwYWVmYzRkYTBlMmQ3NTllYmVhOGJiZDE0ZTg1NjE4MjczOTVlNzM0ZTRlMWQ0MmRlMmYwNTk5Mw",
    +    "expires_in": 3600,
    +    "refresh_token": "ODBjODU1NWUwNmUzZTBkNDQ5YWVlZTVlMjQ2Y2I0OWM2NTM1ZGM2M2Y3MDhjMTViM2U2MzYxYzRkMDk5ODRlZg",
    +    "scope": null,
    +    "token_type": "bearer"
    +}
    +

    +

    {% trans %}The access_token is useful to do a call to the API endpoint. For example:{% endtrans %}

    +

    +

    http GET http://v2.wallabag.org/api/entries.json \
    +    "Authorization:Bearer ZWFjNjA3ZWMwYWVmYzRkYTBlMmQ3NTllYmVhOGJiZDE0ZTg1NjE4MjczOTVlNzM0ZTRlMWQ0MmRlMmYwNTk5Mw"
    +

    +

    {% trans %}This call will return all the entries for your user.{% endtrans %}

    +

    {% trans with {'%link%': path('nelmio_api_doc_index')} %}If you want to see all the API endpoints, you can have a look to our API documentation.{% endtrans %}

    +

    {% trans %}Back{% endtrans %}

    +
    + +
    +
    +
    + + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig new file mode 100644 index 000000000..2e7dbcab7 --- /dev/null +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Developer/index.html.twig @@ -0,0 +1,68 @@ +{% extends "WallabagCoreBundle::layout.html.twig" %} + +{% block title %}{% trans %}Developer{% endtrans %}{% endblock %} + +{% block content %} +
    +
    +
    + +
    +

    {% trans %}Welcome to the wallabag API{% endtrans %}

    + +

    {% trans %}Documentation{% endtrans %}

    + + + +

    {% trans %}Clients{% endtrans %}

    + + +

    {% trans %}Existing clients{% endtrans %}

    + {% if clients %} +
      + {% for client in clients %} +
    • +
      #{{ client.id }}
      +
      + + + + + + + + + + + + + + + + + +
      {% trans %}Client ID{% endtrans %}{{ client.id }}_{{ client.randomId }}
      {% trans %}Client secret{% endtrans %}{{ client.secret }}
      {% trans %}Redirect URIs{% endtrans %}{{ client.redirectUris|json_encode() }}
      {% trans %}Grant type allowed{% endtrans %}{{ client.allowedGrantTypes|json_encode() }}
      +

      + {% trans %}You have the ability to remove this client. This action is IRREVERSIBLE !{% endtrans %}
      + {% trans %}If you remove it, every app configured with that client won't be able to auth on your wallabag.{% endtrans %}
      + {% trans %}Remove this client{% endtrans %} +

      +
      +
    • + {% endfor %} +
    + {% else %} + {% trans %}No client yet.{% endtrans %} + {% endif %} +
    + +
    +
    +
    + +{% endblock %} diff --git a/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/quickstart.html.twig b/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/quickstart.html.twig index 3d21271ad..dea4242b4 100644 --- a/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/quickstart.html.twig +++ b/src/Wallabag/CoreBundle/Resources/views/themes/material/Static/quickstart.html.twig @@ -41,6 +41,10 @@
  • {% trans %}Migrate from wallabag v1{% endtrans %}
  • {% trans %}Migrate from wallabag v2{% endtrans %}
  • +

    {% trans %}Developers{% endtrans %}

    +

    {% trans %}Full documentation{% endtrans %}