From 0a8c71b7357846b9cd11785563320183df22ac33 Mon Sep 17 00:00:00 2001 From: Mal <=> Date: Wed, 19 Aug 2020 23:57:00 +0200 Subject: [PATCH] Endpoint for user creation added --- .../classes/controller/UserPostController.php | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 backend/classes/controller/UserPostController.php diff --git a/backend/classes/controller/UserPostController.php b/backend/classes/controller/UserPostController.php new file mode 100644 index 0000000..af4d36e --- /dev/null +++ b/backend/classes/controller/UserPostController.php @@ -0,0 +1,54 @@ +response->getStatus() !== ServerStatus::OK) { + return; + } + + $json = json_decode($this->requestBody); + + try { + $user = new User(); + + $user->setUsername($json->username); + $user->setPassword(Password::GetHash($json->password)); + $user->setEmail($json->email); + $user->setJabberAddress($json->jabberAddress); + $user->Save(); + + $this->response = new ApiJsonResponse(); + $this->response->setParameter('userId', $user->getUserId()); + } catch (DatabaseException $e) { + $this->response = new ApiJsonResponse(); + $this->response->setParameter('success', false); + $this->response->setMessage($e->getMessage()); + + switch ($e->getCode()) { + case DatabaseException::CONNECTION_FAILED: + $this->response->setStatus(ServerStatus::INTERNAL_ERROR); + break; + default: + $this->response->setStatus(ServerStatus::INTERNAL_ERROR); + } + } catch (Throwable $e) { + $this->response = new ApiJsonResponse(ServerStatus::BAD_REQUEST); + $this->response->setParameter('success', false); + $this->response->setMessage($e->getMessage()); + } + } +} \ No newline at end of file