/**
  * @brief Run service
  */
 public function run()
 {
     //
     // Check if given url is valid
     //
     if (!$this->urlParser->isValid()) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_DATA);
         return false;
     }
     $syncUserHash = $this->urlParser->getUserName();
     if (User::authenticateUser($syncUserHash) == false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         return false;
     }
     $userId = User::userHashToId($syncUserHash);
     if ($userId == false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         return false;
     }
     Storage::deleteOldWbo();
     //
     // Map request to functions
     //
     // Info case: https://server/pathname/version/username/info/
     if ($this->urlParser->commandCount() == 2 && $this->urlParser->getCommand(0) == 'info') {
         if (Utils::getRequestMethod() != 'GET') {
             Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
             return false;
         }
         switch ($this->urlParser->getCommand(1)) {
             case 'collections':
                 $this->getInfoCollections($userId);
                 break;
             default:
                 Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
         }
     } else {
         if ($this->urlParser->commandCount() == 1 && $this->urlParser->getCommand(0) == 'storage') {
             switch (Utils::getRequestMethod()) {
                 case 'DELETE':
                     $this->deleteStorage($userId);
                     break;
                 default:
                     Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
             }
         } else {
             if ($this->urlParser->commandCount() == 2 && $this->urlParser->getCommand(0) == 'storage') {
                 $collectionName = $this->urlParser->getCommand(1);
                 $modifiers = $this->urlParser->getCommandModifiers(1);
                 $collectionId = Storage::collectionNameToIndex($userId, $collectionName);
                 switch (Utils::getRequestMethod()) {
                     case 'GET':
                         $this->getCollection($userId, $collectionId, $modifiers);
                         break;
                     case 'POST':
                         $this->postCollection($userId, $collectionId);
                         break;
                     case 'DELETE':
                         $this->deleteCollection($userId, $collectionId, $modifiers);
                         break;
                     default:
                         Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                 }
             } else {
                 if ($this->urlParser->commandCount() == 3 && $this->urlParser->getCommand(0) == 'storage') {
                     $collectionName = $this->urlParser->getCommand(1);
                     $wboId = $this->urlParser->getCommand(2);
                     $collectionId = Storage::collectionNameToIndex($userId, $collectionName);
                     switch (Utils::getRequestMethod()) {
                         case 'GET':
                             $this->getWBO($userId, $collectionId, $wboId);
                             break;
                         case 'PUT':
                             $this->putWBO($userId, $collectionId, $wboId);
                             break;
                         case 'DELETE':
                             $this->deleteWBO($userId, $collectionId, $wboId);
                             break;
                         default:
                             Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                     }
                 } else {
                     Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                 }
             }
         }
     }
     return true;
 }
Example #2
0
 /**
  *  @brief Detete user
  *
  *  DELETE https://server/pathname/version/username
  *
  *  Deletes the user account.
  *  NOTE: Requires simple authentication with the username and password associated with the account.
  *
  *  Return value:
  *  0 on success
  *
  *  Possible errors:
  *    503: there was an error removing the user
  *    404: the user does not exist in the database
  *    401: authentication failed
  *
  *  @param string $userName
  */
 private function deleteUser($syncUserHash)
 {
     if (User::syncUserExists($syncUserHash) == false) {
         Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
         return true;
     }
     if (User::authenticateUser($syncUserHash) == false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         return true;
     }
     $userId = User::userHashToId($syncUserHash);
     if ($userId == false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         return true;
     }
     if (Storage::deleteStorage($userId) == false) {
         Utils::changeHttpStatus(Utils::STATUS_MAINTENANCE);
         return true;
     }
     if (User::deleteUser($userId) == false) {
         Utils::changeHttpStatus(Utils::STATUS_MAINTENANCE);
         return true;
     }
     OutputData::write('0');
     return true;
 }