/** * create user * * @param Tinebase_Model_FullUser $_account the account * @param string $_password the new password * @param string $_passwordRepeat the new password again * @return Tinebase_Model_FullUser */ public function create(Tinebase_Model_FullUser $_user, $_password, $_passwordRepeat) { $this->checkRight('MANAGE_ACCOUNTS'); // avoid forging accountId, get's created in backend unset($_user->accountId); try { $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $contact = $this->createOrUpdateContact($_user); $_user->contact_id = $contact->getId(); } $user = $this->_userBackend->addUser($_user); // make sure primary groups is in the list of groupmemberships $groups = array_unique(array_merge(array($user->accountPrimaryGroup), (array) $_user->groups)); Admin_Controller_Group::getInstance()->setGroupMemberships($user, $groups); Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString()); } throw $e; } $event = new Admin_Event_AddAccount(array('account' => $user)); Tinebase_Event::fireEvent($event); if (!empty($_password) && !empty($_passwordRepeat)) { $this->setAccountPassword($user, $_password, $_passwordRepeat); } return $user; }
protected function _createAndStoreDummyUsers($count) { for ($i = 0; $i < $count; $i++) { $dummyUser = new Tinebase_Model_FullUser(array('accountLoginName' => 'dummy_' . $i, 'accountStatus' => 'enabled', 'accountExpires' => NULL, 'accountPrimaryGroup' => Tinebase_Group::getInstance()->getGroupByName('Users')->id, 'accountLastName' => 'Dummy', 'accountFirstName' => 'No.' . $i, 'accountEmailAddress' => '*****@*****.**')); $this->_uit->addUser($dummyUser); $this->_objects[] = $dummyUser; } }
/** * create user * * @param Tinebase_Model_FullUser $_account the account * @param string $_password the new password * @param string $_passwordRepeat the new password again * @return Tinebase_Model_FullUser */ public function create(Tinebase_Model_FullUser $_user, $_password, $_passwordRepeat) { $this->checkRight('MANAGE_ACCOUNTS'); // avoid forging accountId, gets created in backend unset($_user->accountId); if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) { Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Create new user ' . $_user->accountLoginName); } if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) { Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' ' . print_r($_user->toArray(), TRUE)); } $this->_checkLoginNameExistance($_user); $this->_checkLoginNameLength($_user); $this->_checkPrimaryGroupExistance($_user); if ($_password != $_passwordRepeat) { throw new Admin_Exception("Passwords don't match."); } else { if (empty($_password)) { $_password = ''; $_passwordRepeat = ''; } } Tinebase_User::getInstance()->checkPasswordPolicy($_password, $_user); try { $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb()); if (Tinebase_Application::getInstance()->isInstalled('Addressbook') === true) { $contact = $this->createOrUpdateContact($_user); $_user->contact_id = $contact->getId(); } Tinebase_Timemachine_ModificationLog::setRecordMetaData($_user, 'create'); $user = $this->_userBackend->addUser($_user); // make sure primary groups is in the list of groupmemberships $groups = array_unique(array_merge(array($user->accountPrimaryGroup), (array) $_user->groups)); Admin_Controller_Group::getInstance()->setGroupMemberships($user, $groups); Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId); } catch (Exception $e) { Tinebase_TransactionManager::getInstance()->rollBack(); Tinebase_Core::getLogger()->err(__METHOD__ . '::' . __LINE__ . ' ' . $e->getMessage()); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . $e->getTraceAsString()); } throw $e; } $event = new Admin_Event_AddAccount(array('account' => $user)); Tinebase_Event::fireEvent($event); $this->setAccountPassword($user, $_password, $_passwordRepeat); return $user; }