コード例 #1
0
ファイル: Json.php プロジェクト: rodrigofns/ExpressoLivre3
 /**
  * save user
  *
  * @param  array $recordData data of Tinebase_Model_FullUser
  * @return array  
  */
 public function saveUser($recordData)
 {
     $password = isset($recordData['accountPassword']) ? $recordData['accountPassword'] : '';
     $account = new Tinebase_Model_FullUser();
     // always re-evaluate fullname
     unset($recordData['accountFullName']);
     try {
         $account->setFromArray($recordData);
         if (isset($recordData['sambaSAM'])) {
             $account->sambaSAM = new Tinebase_Model_SAMUser($recordData['sambaSAM']);
         }
         if (isset($recordData['emailUser'])) {
             $account->emailUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->imapUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->smtpUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
         }
     } catch (Tinebase_Exception_Record_Validation $e) {
         // invalid data in some fields sent from client
         $result = array('errors' => $account->getValidationErrors(), 'errorMessage' => 'invalid data for some fields', 'status' => 'failure');
         return $result;
     }
     if ($account->getId() == NULL) {
         if (!Tinebase_User_Registration::getInstance()->checkUniqueUsername($account->accountLoginName)) {
             $result = array('errors' => 'invalid username', 'errorMessage' => 'Username already used.', 'status' => 'failure');
             return $result;
         }
         $account = Admin_Controller_User::getInstance()->create($account, $password, $password);
     } else {
         $account = Admin_Controller_User::getInstance()->update($account, $password, $password);
     }
     // after user update or creation add user to selected roles
     if (isset($recordData['accountRoles']) && $recordData['accountRoles']) {
         Tinebase_Acl_Roles::getInstance()->setRoleMemberships(array('id' => $account->accountId, 'type' => Tinebase_Acl_Rights::ACCOUNT_TYPE_USER), $recordData['accountRoles']);
     }
     $result = $this->_recordToJson($account);
     // add primary group to account for the group selection combo box
     $group = Tinebase_Group::getInstance()->getGroupById($account->accountPrimaryGroup);
     // add user groups
     $userGroups = Tinebase_Group::getInstance()->getMultiple(Tinebase_Group::getInstance()->getGroupMemberships($account->accountId))->toArray();
     // add user roles
     $userRoles = Tinebase_Acl_Roles::getInstance()->getMultiple(Tinebase_Acl_Roles::getInstance()->getRoleMemberships($account->accountId))->toArray();
     // encode the account array
     $result['accountPrimaryGroup'] = $group;
     // encode the groups array
     $result['groups'] = array('results' => $userGroups, 'totalcount' => count($userGroups));
     // encode the roles array
     $result['accountRoles'] = array('results' => $userRoles, 'totalcount' => count($userRoles));
     return $result;
 }
コード例 #2
0
 /**
  * save user
  *
  * @param  array $recordData data of Tinebase_Model_FullUser
  * @return array  
  */
 public function saveUser($recordData)
 {
     $password = isset($recordData['accountPassword']) ? $recordData['accountPassword'] : '';
     $account = new Tinebase_Model_FullUser();
     // always re-evaluate fullname
     unset($recordData['accountFullName']);
     try {
         $account->setFromJsonInUsersTimezone($recordData);
         if (isset($recordData['sambaSAM'])) {
             $account->sambaSAM = new Tinebase_Model_SAMUser($recordData['sambaSAM']);
         }
         if (isset($recordData['emailUser'])) {
             $account->emailUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->imapUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
             $account->smtpUser = new Tinebase_Model_EmailUser($recordData['emailUser']);
         }
     } catch (Tinebase_Exception_Record_Validation $e) {
         // invalid data in some fields sent from client
         $result = array('errors' => $account->getValidationErrors(), 'errorMessage' => 'invalid data for some fields', 'status' => 'failure');
         return $result;
     }
     // this needs long 3execution time because cache invalidation may take long
     // @todo remove this when "0007266: make groups / group memberships cache cleaning more efficient" is resolved
     $oldMaxExcecutionTime = Tinebase_Core::setExecutionLifeTime(300);
     // 5 minutes
     if ($account->getId() == NULL) {
         $account = Admin_Controller_User::getInstance()->create($account, $password, $password);
     } else {
         $account = Admin_Controller_User::getInstance()->update($account, $password, $password);
     }
     $result = $this->_recordToJson($account);
     // add primary group to account for the group selection combo box
     $group = Tinebase_Group::getInstance()->getGroupById($account->accountPrimaryGroup);
     // add user groups
     $userGroups = Tinebase_Group::getInstance()->getMultiple(Tinebase_Group::getInstance()->getGroupMemberships($account->accountId))->toArray();
     // add user roles
     $userRoles = Tinebase_Acl_Roles::getInstance()->getMultiple(Tinebase_Acl_Roles::getInstance()->getRoleMemberships($account->accountId))->toArray();
     // encode the account array
     $result['accountPrimaryGroup'] = $group->toArray();
     // encode the groups array
     $result['groups'] = array('results' => $userGroups, 'totalcount' => count($userGroups));
     // encode the roles array
     $result['accountRoles'] = array('results' => $userRoles, 'totalcount' => count($userRoles));
     Tinebase_Core::setExecutionLifeTime($oldMaxExcecutionTime);
     return $result;
 }
コード例 #3
0
 /**
  * updates an user
  * 
  * this function updates an user 
  *
  * @param Tinebase_Model_FullUser $_user
  * @return Tinebase_Model_FullUser
  * @throws 
  */
 public function updateUserInSqlBackend(Tinebase_Model_FullUser $_user)
 {
     if (!$_user->isValid()) {
         throw new Tinebase_Exception_Record_Validation('Invalid user object. ' . print_r($_user->getValidationErrors(), TRUE));
     }
     $accountId = Tinebase_Model_User::convertUserIdToInt($_user);
     $oldUser = $this->getFullUserById($accountId);
     if (empty($_user->contact_id)) {
         $_user->visibility = 'hidden';
         $_user->contact_id = null;
     }
     $accountData = $this->_recordToRawData($_user);
     // don't update id
     unset($accountData['id']);
     // ignore all other states (expired and blocked)
     if ($_user->accountStatus == Tinebase_User::STATUS_ENABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
         if ($oldUser->accountStatus === Tinebase_User::STATUS_BLOCKED) {
             $accountData[$this->rowNameMapping['loginFailures']] = 0;
         } elseif ($oldUser->accountStatus === Tinebase_User::STATUS_EXPIRED) {
             $accountData[$this->rowNameMapping['accountExpires']] = null;
         }
     } elseif ($_user->accountStatus == Tinebase_User::STATUS_DISABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($accountData, true));
     }
     try {
         $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $accountId));
         $accountsTable->update($accountData, $where);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     return $this->getUserById($accountId, 'Tinebase_Model_FullUser');
 }
コード例 #4
0
 /**
  * updates an user
  * 
  * this function updates an user 
  *
  * @param Tinebase_Model_FullUser $_user
  * @return Tinebase_Model_FullUser
  * @throws 
  */
 public function updateUserInSqlBackend(Tinebase_Model_FullUser $_user)
 {
     if (!$_user->isValid()) {
         throw new Tinebase_Exception_Record_Validation('Invalid user object. ' . print_r($_user->getValidationErrors(), TRUE));
     }
     $accountId = Tinebase_Model_User::convertUserIdToInt($_user);
     $oldUser = $this->getFullUserById($accountId);
     $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
     if (empty($_user->contact_id)) {
         $_user->visibility = 'hidden';
         $_user->contact_id = null;
     }
     $accountData = array('login_name' => $_user->accountLoginName, 'expires_at' => $_user->accountExpires instanceof DateTime ? $_user->accountExpires->get(Tinebase_Record_Abstract::ISO8601LONG) : NULL, 'primary_group_id' => $_user->accountPrimaryGroup, 'home_dir' => $_user->accountHomeDirectory, 'login_shell' => $_user->accountLoginShell, 'openid' => $_user->openid, 'visibility' => $_user->visibility, 'contact_id' => $_user->contact_id, $this->rowNameMapping['accountDisplayName'] => $_user->accountDisplayName, $this->rowNameMapping['accountFullName'] => $_user->accountFullName, $this->rowNameMapping['accountFirstName'] => $_user->accountFirstName, $this->rowNameMapping['accountLastName'] => $_user->accountLastName, $this->rowNameMapping['accountEmailAddress'] => $_user->accountEmailAddress);
     // ignore all other states (expired and blocked)
     if ($_user->accountStatus == Tinebase_User::STATUS_ENABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
         if ($oldUser->accountStatus === Tinebase_User::STATUS_BLOCKED) {
             $accountData[$this->rowNameMapping['loginFailures']] = 0;
         } elseif ($oldUser->accountStatus === Tinebase_User::STATUS_EXPIRED) {
             $accountData[$this->rowNameMapping['accountExpires']] = null;
         }
     } elseif ($_user->accountStatus == Tinebase_User::STATUS_DISABLED) {
         $accountData[$this->rowNameMapping['accountStatus']] = $_user->accountStatus;
     }
     if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) {
         Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($accountData, true));
     }
     try {
         $accountsTable = new Tinebase_Db_Table(array('name' => SQL_TABLE_PREFIX . 'accounts'));
         $where = array($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' = ?', $accountId));
         $accountsTable->update($accountData, $where);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     return $this->getUserById($accountId, 'Tinebase_Model_FullUser');
 }