From 18dd151c906444a1d8c85392b1ba5e4acd3b2862 Mon Sep 17 00:00:00 2001 From: randomchars42 Date: Sat, 17 Jun 2017 13:01:40 +0200 Subject: [PATCH] fix bug crashing the api when creating a user with ROLE_USER --- src/OlmServer/OlmApi.php | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/OlmServer/OlmApi.php b/src/OlmServer/OlmApi.php index 8e1b241..8a9e144 100644 --- a/src/OlmServer/OlmApi.php +++ b/src/OlmServer/OlmApi.php @@ -1293,8 +1293,22 @@ public function controllerUsersPost(\Symfony\Component\HttpFoundation\Request $r $data['enabled'] = 0; $data = $this->entriesPrepareForClient(array($data), 'users')[0]; + + $table = 'users'; + $data = $this->checkData($data, $table, true); + $this->checkPermissionsRole($request->get("_route")); + + $id = $this->entryCreate($data, $table); + + if ($id === -1) { + $this->sendError(self::RESPONSE_ITEM_EXISTS); + } + mail($data['email'], '[Olm] PW', "Hallo " . $data['username'] . ",\nbitte melde Dich mit: $password an und ändere Dein Passwort!"); - return $this->controllerDefaultPost($request, $data); + $entry = $this->entryFetchById($id, $table); + $entry = $this->entriesPrepareForClient(array($entry), $table)[0]; + + return $this->app->json($entry, 201); } public function controllerUsersPatch(\Symfony\Component\HttpFoundation\Request $request, string $id) {