$response->getBody()->write(json_encode("Missing password")); return $response->withStatus(400); } $dataStore = DataStore::getInstance(); $user = $dataStore->getUser($email); if ($user) { $response->getBody()->write(json_encode("User with the same email already exists")); return $response->withStatus(400); } $passwordHash = password_hash($password, PASSWORD_DEFAULT); $dataStore->createUser($email, $passwordHash, $name, "dutings"); $user = $dataStore->getUser($email); unset($user['password']); $response->getBody()->write(json_encode($user)); }); $hasAuthToken = function (Request $request, Response $response, $next) use($app, $settings) { $authTokens = $request->getHeader('AUTH_TOKEN'); if (count($authTokens) === 0) { return $response->withStatus(401); } $authToken = $authTokens[0]; $dataStore = DataStore::getInstance(); $token = $dataStore->getAuthToken($authToken); if (!$token) { return $response->withStatus(401); } $dataStore->cache["user_id"] = $token['user_id']; return $next($request, $response); }; $app->group("/api", function () use($app, $settings) { })->add($hasAuthToken);