X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;ds=sidebyside;f=src%2FWallabag%2FApiBundle%2FController%2FUserRestController.php;h=3a4dafcd083887e92923e0e23f30adef50292834;hb=4ac0e659638a4b79f1ca58b673fdc12d07bbb06b;hp=becbbb9ef4c0d77f5f024fe06cef1ba81e885f47;hpb=0c00e5251671c3648eabb8888271c09137ad902d;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/ApiBundle/Controller/UserRestController.php b/src/Wallabag/ApiBundle/Controller/UserRestController.php index becbbb9e..3a4dafcd 100644 --- a/src/Wallabag/ApiBundle/Controller/UserRestController.php +++ b/src/Wallabag/ApiBundle/Controller/UserRestController.php @@ -6,10 +6,10 @@ use FOS\UserBundle\Event\UserEvent; use FOS\UserBundle\FOSUserEvents; use JMS\Serializer\SerializationContext; use Nelmio\ApiDocBundle\Annotation\ApiDoc; -use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\JsonResponse; -use Wallabag\UserBundle\Entity\User; +use Symfony\Component\HttpFoundation\Request; use Wallabag\ApiBundle\Entity\Client; +use Wallabag\UserBundle\Entity\User; class UserRestController extends WallabagRestController { @@ -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)"} * } * ) * @@ -45,7 +46,7 @@ class UserRestController extends WallabagRestController public function putUserAction(Request $request) { if (!$this->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) { - $json = $this->get('serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json'); + $json = $this->get('jms_serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json'); return (new JsonResponse()) ->setJson($json) @@ -76,7 +77,7 @@ class UserRestController extends WallabagRestController $view->setFormat('json'); // handle errors in a more beautiful way than the default view - $data = json_decode($this->handleView($view)->getContent(), true)['children']; + $data = json_decode($this->handleView($view)->getContent(), true)['errors']['children']; $errors = []; if (isset($data['username']['errors'])) { @@ -91,7 +92,7 @@ class UserRestController extends WallabagRestController $errors['password'] = $this->translateErrors($data['plainPassword']['children']['first']['errors']); } - $json = $this->get('serializer')->serialize(['error' => $errors], 'json'); + $json = $this->get('jms_serializer')->serialize(['error' => $errors], 'json'); return (new JsonResponse()) ->setJson($json) @@ -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); @@ -126,7 +127,7 @@ class UserRestController extends WallabagRestController */ private function sendUser(User $user, $group = 'user_api', $status = JsonResponse::HTTP_OK) { - $json = $this->get('serializer')->serialize( + $json = $this->get('jms_serializer')->serialize( $user, 'json', SerializationContext::create()->setGroups([$group])