예제 #1
0
 /**
  * Activate a user on the specified site and validate email if it was empty, otherwise login
  * @param string $username
  * @param string $password
  * @param string $email
  * @param Website $website
  * @param Application $app
  * @param DeliveryInterface $delivery
  * @return string|boolean $userId|false otherwise
  */
 public static function activate($username, $password, $email, $website, $app, DeliveryInterface $delivery = null)
 {
     CodeGuard::checkEmptyAndThrow($username, 'username');
     CodeGuard::checkEmptyAndThrow($password, 'password');
     CodeGuard::checkEmptyAndThrow($email, 'email');
     CodeGuard::checkNullAndThrow($website, 'website');
     $identityCheck = self::checkIdentity($username, $email, $website);
     if ($website->allowSignupFromOtherSites && $identityCheck->usernameExists && !$identityCheck->usernameExistsOnThisSite && ($identityCheck->emailIsEmpty || $identityCheck->emailMatchesAccount)) {
         $user = new PasswordModel();
         if ($user->readByProperty('username', $username)) {
             if ($user->verifyPassword($password)) {
                 $user = new UserModel($user->id->asString());
                 $user->siteRole[$website->domain] = $website->userDefaultSiteRole;
                 if ($identityCheck->emailIsEmpty) {
                     $user->emailPending = $email;
                 }
                 $user->write();
                 // if website has a default project then add them to that project
                 $project = ProjectModel::getDefaultProject($website);
                 $url = '/app';
                 if ($project) {
                     $project->addUser($user->id->asString(), ProjectRoles::CONTRIBUTOR);
                     $user->addProject($project->id->asString());
                     $project->write();
                     $user->write();
                     $url = '/app/' . $project->appName . '/' . $project->id->asString();
                 }
                 if ($identityCheck->emailIsEmpty) {
                     Communicate::sendSignup($user, $website, $delivery);
                 }
                 if ($identityCheck->emailMatchesAccount) {
                     Auth::login($app, $username, $password);
                     return Auth::result(Auth::LOGIN_SUCCESS, $url, 'location');
                 }
                 return Auth::result(Auth::LOGIN_FAIL_USER_UNAUTHORIZED, '', 'location');
             }
         }
     }
     return false;
 }
 /**
  * If the project is archived, throws an exception because the project should not be modified
  * @param ProjectModel $project
  * @throws ResourceNotAvailableException
  */
 public static function checkIfArchivedAndThrow($project)
 {
     CodeGuard::checkNullAndThrow($project, 'project');
     CodeGuard::checkTypeAndThrow($project, '\\Api\\Model\\Shared\\ProjectModel');
     if ($project->isArchived) {
         throw new ResourceNotAvailableException("This {$project->appName} project '{$project->projectName}'\n" . "is archived and cannot be modified. Please\n" . "contact a system administrator to re-publish\n" . "this project if you want to make further updates.");
     }
 }
예제 #3
0
 /**
  * @param array $data
  * @param string $id
  * @param int $keyType
  * @param string $rootId
  * @param string $property
  * @return string
  */
 protected function update($data, $id, $keyType, $rootId, $property)
 {
     CodeGuard::checkTypeAndThrow($rootId, 'string');
     CodeGuard::checkTypeAndThrow($id, 'string');
     if ($keyType == self::ID_IN_KEY) {
         if (empty($rootId)) {
             $mongoid = self::mongoId($id);
             $result = $this->_collection->update(array('_id' => $mongoid), array('$set' => $data), array('upsert' => true, 'multiple' => false, 'safe' => true));
             //$id = isset($result['upserted']) ? $result['upserted'].$id : $id;
             $id = $mongoid->__toString();
         } else {
             CodeGuard::checkNullAndThrow($id, 'id');
             CodeGuard::checkNullAndThrow($property, 'property');
             $subKey = $property . '.' . $id;
             $result = $this->_collection->update(array('_id' => self::mongoId($rootId)), array('$set' => array($subKey => $data)), array('upsert' => false, 'multiple' => false, 'safe' => true));
         }
     } else {
         CodeGuard::checkNullAndThrow($id, 'id');
         $result = $this->_collection->update(array('_id' => self::mongoId($rootId)), array('$set' => array($property . '$' . $id => $data)), array('upsert' => false, 'multiple' => false, 'safe' => true));
     }
     return $id;
 }
 /**
  * @param array $data
  * @param string $id
  * @param int $keyType
  * @param string $rootId
  * @param string $property
  * @return string
  */
 protected function update($data, $id, $keyType, $rootId, $property)
 {
     CodeGuard::checkTypeAndThrow($rootId, 'string');
     CodeGuard::checkTypeAndThrow($id, 'string');
     if ($keyType == self::ID_IN_KEY) {
         if (empty($rootId)) {
             $mongoid = self::mongoID($id);
             $filter = array('_id' => $mongoid);
             $updateCommand = array('$set' => $data);
             $options = array('upsert' => true);
             $this->_collection->updateOne($filter, $updateCommand, $options);
             $id = $mongoid->__toString();
         } else {
             CodeGuard::checkNullAndThrow($id, 'id');
             CodeGuard::checkNullAndThrow($property, 'property');
             $subKey = $property . '.' . $id;
             $filter = array('_id' => self::mongoID($rootId));
             $updateCommand = array('$set' => array($subKey => $data));
             $this->_collection->updateOne($filter, $updateCommand);
         }
     } else {
         CodeGuard::checkNullAndThrow($id, 'id');
         $filter = array('_id' => self::mongoID($rootId));
         $updateCommand = array('$set' => array($property . '$' . $id => $data));
         $this->_collection->updateOne($filter, $updateCommand);
     }
     return $id;
 }