aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/ApiBundle/Controller/UserRestController.php
diff options
context:
space:
mode:
authorJérémy Benoist <j0k3r@users.noreply.github.com>2017-06-06 15:25:05 +0200
committerGitHub <noreply@github.com>2017-06-06 15:25:05 +0200
commit6ed2627bb35561e32d702fbe67247349dd67453e (patch)
tree75d8c130d26f0591fe858cd9eacf6b97aed4af7e /src/Wallabag/ApiBundle/Controller/UserRestController.php
parent9fe87bc2e20fa95573287a61ef9798cc15648187 (diff)
parent438329be467d77595f549da48a6b49f38ece9b55 (diff)
downloadwallabag-6ed2627bb35561e32d702fbe67247349dd67453e.tar.gz
wallabag-6ed2627bb35561e32d702fbe67247349dd67453e.tar.zst
wallabag-6ed2627bb35561e32d702fbe67247349dd67453e.zip
Merge pull request #3177 from wallabag/api-create-user-update
API user creation behing a toggle
Diffstat (limited to 'src/Wallabag/ApiBundle/Controller/UserRestController.php')
-rw-r--r--src/Wallabag/ApiBundle/Controller/UserRestController.php23
1 files changed, 15 insertions, 8 deletions
diff --git a/src/Wallabag/ApiBundle/Controller/UserRestController.php b/src/Wallabag/ApiBundle/Controller/UserRestController.php
index a1b78e3f..8f675b8d 100644
--- a/src/Wallabag/ApiBundle/Controller/UserRestController.php
+++ b/src/Wallabag/ApiBundle/Controller/UserRestController.php
@@ -43,16 +43,18 @@ class UserRestController extends WallabagRestController
43 */ 43 */
44 public function putUserAction(Request $request) 44 public function putUserAction(Request $request)
45 { 45 {
46 if (!$this->container->getParameter('fosuser_registration')) { 46 if (!$this->getParameter('fosuser_registration') || !$this->get('craue_config')->get('api_user_registration')) {
47 $json = $this->get('serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json'); 47 $json = $this->get('serializer')->serialize(['error' => "Server doesn't allow registrations"], 'json');
48 48
49 return (new JsonResponse())->setJson($json)->setStatusCode(403); 49 return (new JsonResponse())
50 ->setJson($json)
51 ->setStatusCode(JsonResponse::HTTP_FORBIDDEN);
50 } 52 }
51 53
52 $userManager = $this->get('fos_user.user_manager'); 54 $userManager = $this->get('fos_user.user_manager');
53 $user = $userManager->createUser(); 55 $user = $userManager->createUser();
54 // enable created user by default 56 // user will be disabled BY DEFAULT to avoid spamming account to be enabled
55 $user->setEnabled(true); 57 $user->setEnabled(false);
56 58
57 $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [ 59 $form = $this->createForm('Wallabag\UserBundle\Form\NewUserType', $user, [
58 'csrf_protection' => false, 60 'csrf_protection' => false,
@@ -90,7 +92,9 @@ class UserRestController extends WallabagRestController
90 92
91 $json = $this->get('serializer')->serialize(['error' => $errors], 'json'); 93 $json = $this->get('serializer')->serialize(['error' => $errors], 'json');
92 94
93 return (new JsonResponse())->setJson($json)->setStatusCode(400); 95 return (new JsonResponse())
96 ->setJson($json)
97 ->setStatusCode(JsonResponse::HTTP_BAD_REQUEST);
94 } 98 }
95 99
96 $userManager->updateUser($user); 100 $userManager->updateUser($user);
@@ -99,17 +103,18 @@ class UserRestController extends WallabagRestController
99 $event = new UserEvent($user, $request); 103 $event = new UserEvent($user, $request);
100 $this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event); 104 $this->get('event_dispatcher')->dispatch(FOSUserEvents::USER_CREATED, $event);
101 105
102 return $this->sendUser($user); 106 return $this->sendUser($user, JsonResponse::HTTP_CREATED);
103 } 107 }
104 108
105 /** 109 /**
106 * Send user response. 110 * Send user response.
107 * 111 *
108 * @param User $user 112 * @param User $user
113 * @param int $status HTTP Status code to send
109 * 114 *
110 * @return JsonResponse 115 * @return JsonResponse
111 */ 116 */
112 private function sendUser(User $user) 117 private function sendUser(User $user, $status = JsonResponse::HTTP_OK)
113 { 118 {
114 $json = $this->get('serializer')->serialize( 119 $json = $this->get('serializer')->serialize(
115 $user, 120 $user,
@@ -117,7 +122,9 @@ class UserRestController extends WallabagRestController
117 SerializationContext::create()->setGroups(['user_api']) 122 SerializationContext::create()->setGroups(['user_api'])
118 ); 123 );
119 124
120 return (new JsonResponse())->setJson($json); 125 return (new JsonResponse())
126 ->setJson($json)
127 ->setStatusCode($status);
121 } 128 }
122 129
123 /** 130 /**