From a8d3fe50df52ec486add5691a3b67fe5205a032e Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Thu, 8 Jun 2017 14:25:44 +0200 Subject: [PATCH] Add ability to name the client --- src/Wallabag/ApiBundle/Controller/UserRestController.php | 7 ++++--- .../ApiBundle/Controller/UserRestControllerTest.php | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Wallabag/ApiBundle/Controller/UserRestController.php b/src/Wallabag/ApiBundle/Controller/UserRestController.php index becbbb9ef..7471f5f62 100644 --- a/src/Wallabag/ApiBundle/Controller/UserRestController.php +++ b/src/Wallabag/ApiBundle/Controller/UserRestController.php @@ -28,13 +28,14 @@ class UserRestController extends WallabagRestController } /** - * Register an user. + * Register an user and create a client. * * @ApiDoc( * requirements={ * {"name"="username", "dataType"="string", "required"=true, "description"="The user's username"}, * {"name"="password", "dataType"="string", "required"=true, "description"="The user's password"}, - * {"name"="email", "dataType"="string", "required"=true, "description"="The user's email"} + * {"name"="email", "dataType"="string", "required"=true, "description"="The user's email"}, + * {"name"="client_name", "dataType"="string", "required"=true, "description"="The client name (to be used by your app)"} * } * ) * @@ -100,7 +101,7 @@ class UserRestController extends WallabagRestController // create a default client $client = new Client($user); - $client->setName('Default client'); + $client->setName($request->request->get('client_name', 'Default client')); $this->getDoctrine()->getManager()->persist($client); diff --git a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php index 9f01a9760..4e65f130e 100644 --- a/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php +++ b/tests/Wallabag/ApiBundle/Controller/UserRestControllerTest.php @@ -85,6 +85,7 @@ class UserRestControllerTest extends WallabagApiTestCase 'username' => 'google', 'password' => 'googlegoogle', 'email' => 'wallabag@google.com', + 'client_name' => 'My client name !!', ]); $this->assertEquals(201, $client->getResponse()->getStatusCode()); @@ -104,7 +105,7 @@ class UserRestControllerTest extends WallabagApiTestCase $this->assertArrayHasKey('client_secret', $content['default_client']); $this->assertArrayHasKey('client_id', $content['default_client']); - $this->assertEquals('Default client', $content['default_client']['name']); + $this->assertEquals('My client name !!', $content['default_client']['name']); $this->assertEquals('application/json', $client->getResponse()->headers->get('Content-Type'));