PHP User::autoCreateUser Examples

PHP User::autoCreateUser - 2 examples found. These are the top rated real world PHP examples of User::autoCreateUser extracted from open source projects. You can rate examples to help us improve the quality of examples.
Example #1
0
 /**
  * @brief Run user service.
  *
  * @return True on successful command parsing, false otherwise.
  */
 public function run()
 {
     // Check if the given URL is valid
     if (!$this->urlParser->isValid()) {
         Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
         Utils::writeLog("URL: Failed to parse URL.");
         return false;
     }
     $syncHash = $this->urlParser->getSyncHash();
     if (User::isAutoCreateUser() && !User::hasSyncAccount($syncHash)) {
         if (User::authenticateUser($syncHash, false) === false) {
             Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
             Utils::writeLog("Couldn't autocreate account for user " . $syncHash . " authentication failed.");
             return false;
         }
         //auto create account
         User::autoCreateUser($syncHash);
     }
     // Map request to functions
     if ($this->urlParser->commandCount() === 0) {
         switch (Utils::getRequestMethod()) {
             case 'GET':
                 $this->findUser($syncHash);
                 break;
             case 'PUT':
                 $this->createUser($syncHash);
                 break;
             case 'DELETE':
                 $this->deleteUser($syncHash);
                 break;
             default:
                 Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                 Utils::writeLog("URL: Invalid HTTP method " . Utils::getRequestMethod() . " for user " . $syncHash . ".");
         }
     } else {
         if ($this->urlParser->commandCount() === 1 && Utils::getRequestMethod() === 'POST') {
             $password = $this->urlParser->getCommand(0);
             $this->changePassword($syncHash, $password);
         } else {
             if ($this->urlParser->commandMatch('/node\\/weave/')) {
                 $this->getSyncServer();
             } else {
                 Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                 Utils::writeLog("URL: Invalid URL.");
             }
         }
     }
     return true;
 }
Example #2
0
 /**
  * @brief Run storage service.
  *
  * @return True on successful command parsing, false otherwise.
  */
 public function run()
 {
     // Check if given url is valid
     if (!$this->urlParser->isValid()) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_DATA);
         Utils::writeLog("URL: Invalid URL.");
         return false;
     }
     // Get Mozilla Sync user hash and authenticate user
     $syncHash = $this->urlParser->getSyncHash();
     if (User::isAutoCreateUser() && !User::hasSyncAccount($syncHash)) {
         if (User::authenticateUser($syncHash, false) === false) {
             Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
             Utils::writeLog("Couldn't autocreate account for user " . $syncHash . " authentication failed.");
             return false;
         }
         //auto create account
         User::autoCreateUser($syncHash);
     }
     if (User::authenticateUser($syncHash) === false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         Utils::writeLog("Could not authenticate user " . $syncHash . ".");
         return false;
     }
     // Convert Sync hash to Sync ID
     $syncId = User::syncHashToSyncId($syncHash);
     if ($syncId === false) {
         Utils::changeHttpStatus(Utils::STATUS_INVALID_USER);
         Utils::writeLog("Could not convert user " . $syncHash . " to Sync ID.");
         return false;
     }
     // Delete old WBO on every run of storage service
     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);
             Utils::writeLog("URL: Invalid HTTP method " . Utils::getRequestMethod() . " for info.");
             return false;
         }
         switch ($this->urlParser->getCommand(1)) {
             case 'collections':
                 $this->getInfoCollections($syncId);
                 break;
             case 'collection_usage':
                 $this->getInfoCollectionUsage($syncId);
                 break;
             case 'collection_counts':
                 $this->getInfoCollectionCounts($syncId);
                 break;
             case 'quota':
                 $this->getInfoQuota($syncId);
                 break;
             default:
                 Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                 Utils::writeLog("URL: Invalid command " . $this->urlParser->getCommand(1) . " for info.");
                 return false;
         }
     } else {
         if ($this->urlParser->commandCount() === 1 && $this->urlParser->getCommand(0) === 'storage') {
             switch (Utils::getRequestMethod()) {
                 case 'DELETE':
                     $this->deleteStorage($syncId);
                     break;
                 default:
                     Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                     Utils::writeLog("URL: Invalid request method " . Utils::getRequestMethod() . " for storage.");
                     return false;
             }
         } else {
             if ($this->urlParser->commandCount() === 2 && $this->urlParser->getCommand(0) === 'storage') {
                 $collectionName = $this->urlParser->getCommand(1);
                 $modifiers = $this->urlParser->getCommandModifiers();
                 $collectionId = Storage::collectionNameToIndex($syncId, $collectionName);
                 switch (Utils::getRequestMethod()) {
                     case 'GET':
                         $this->getCollection($syncId, $collectionId, $modifiers);
                         break;
                     case 'POST':
                         $this->postCollection($syncId, $collectionId);
                         break;
                     case 'DELETE':
                         $this->deleteCollection($syncId, $collectionId, $modifiers);
                         break;
                     default:
                         Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                         Utils::writeLog("URL: Invalid request method" . Utils::getRequestMethod() . " for collection.");
                         return false;
                 }
             } else {
                 if ($this->urlParser->commandCount() === 3 && $this->urlParser->getCommand(0) === 'storage') {
                     $collectionName = $this->urlParser->getCommand(1);
                     $wboId = $this->urlParser->getCommand(2);
                     $collectionId = Storage::collectionNameToIndex($syncId, $collectionName);
                     switch (Utils::getRequestMethod()) {
                         case 'GET':
                             $this->getWBO($syncId, $collectionId, $wboId);
                             break;
                         case 'PUT':
                             $this->putWBO($syncId, $collectionId, $wboId);
                             break;
                         case 'DELETE':
                             $this->deleteWBO($syncId, $collectionId, $wboId);
                             break;
                         default:
                             Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                             Utils::writeLog("URL: Invalid request method" . Utils::getRequestMethod() . " for WBO.");
                             return false;
                     }
                 } else {
                     Utils::changeHttpStatus(Utils::STATUS_NOT_FOUND);
                     Utils::writeLog("URL: Invalid storage service request. Sent " . (string) $this->urlParser->commandCount() . " commands in URL\t" . Utils::getSyncUrl() . ": " . var_export($this->urlParser->getCommands(), true));
                     return false;
                 }
             }
         }
     }
     return true;
 }