diff --git a/app/helpers.php b/app/helpers.php new file mode 100644 index 0000000..baadf85 --- /dev/null +++ b/app/helpers.php @@ -0,0 +1,31 @@ +post('/user', function (Request $req, Response $res) { - $req_body = $req->getParsedBody(); - if (!array_key_exists('email', $req_body) || !array_key_exists('hash', $req_body) || !array_key_exists('username', $req_body)) { + if (!Helpers::validJson((string) $req->getBody(), array("email", "hash", "username"))) { return $res->withStatus(400); } + + $req_body = $req->getParsedBody(); $code = (new UserGateway)->createUser($req_body['email'], $req_body['hash'], $req_body['username']); if ($code === -1) return $res->withStatus(409);