/** * @param Account $account * @return bool */ protected function _CreateAccount($account) { require_once WM_ROOTPATH . 'common/class_account.php'; require_once WM_ROOTPATH . 'common/class_dbstorage.php'; require_once WM_ROOTPATH . 'common/class_mailprocessor.php'; $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { throw new WebMailModelException('settings error'); } if (!$settings->IncludeLang()) { throw new WebMailModelException('lang error'); } $dbStorage =& DbStorageCreator::CreateDatabaseStorage($account); if ($dbStorage && $dbStorage->Connect()) { $domain =& $dbStorage->SelectDomainByName(EmailAddress::GetDomainFromEmail($account->Email)); if (null !== $domain) { $domain->UpdateAccount($account, $settings); } } else { throw new WebMailModelException(getGlobalError()); } $validate = $account->ValidateData(); if ($validate !== true) { throw new WebMailModelException($validate); } if ($account->IsInternal) { require_once WM_ROOTPATH . 'common/class_exim.php'; $aExplodeArray = explode('@', $account->MailIncLogin, 2); if (!isset($aExplodeArray[1]) || !CExim::CreateUserShell($aExplodeArray[0], $aExplodeArray[1], $account->MailboxLimit)) { throw new WebMailModelException(CantCreateUser); } $dbStorage->InsertAccountData($account); } $processor = new MailProcessor($account); if ($processor && $processor->MailStorage->Connect()) { $inboxSync = $account->GetDefaultFolderSync($settings); $user = new User(); $user->Id = $account->IdUser; if (!$dbStorage->IsSettingsExists($account->IdUser)) { if (!$dbStorage->InsertSettings($account)) { throw new WebMailModelException(getGlobalError()); } } if ($user->CreateAccount($account, $inboxSync, true)) { return true; } } throw new WebMailModelException(getGlobalError()); }
function DoNewAccount() { $_dbStorage = $_settings = $_xmlObj = $_xmlRes = $_accountId = null; $this->_initFuncArgs($_dbStorage, $_settings, $_xmlObj, $_xmlRes, $_accountId); $_account =& CXmlProcessing::AccountCheckAndLoad($_xmlRes, $_accountId); if (!$_account->AllowChangeSettings || !$_settings->AllowUsersAddNewAccounts) { CXmlProcessing::PrintErrorAndExit(PROC_ERROR_ACCT_CREATE, $_xmlRes); } if (!$_account) { CXmlProcessing::PrintErrorAndExit('', $_xmlRes, 2); } $_dbStorage =& DbStorageCreator::CreateDatabaseStorage($_account); if ($_account->IsDemo) { CXmlProcessing::GetAccountList($_dbStorage, $_xmlRes, $_account, $_account->Id); break; } $_newAccount = new Account(); $_newAccount->DefaultAccount = false; CXmlProcessing::UpdateAccountFromRequest($_xmlObj->XmlRoot, $_newAccount); if (!$_settings->AllowUsersChangeAccountsDef) { $_newAccount->DefaultAccount = false; } $_domain =& $_dbStorage->SelectDomainByName(EmailAddress::GetDomainFromEmail($_newAccount->Email)); if ($_domain && !$_domain->IsInternal()) { $_domain->UpdateAccount($_newAccount, $_settings); } $_newAccount->ImapQuota = 0; $_accountNode =& $_xmlObj->XmlRoot->GetChildNodeByTagName('account'); $_user = new User(); $_user->Id = $_account->IdUser; $_SESSION[USER_ID] = $_account->IdUser; $_newAccount->IdUser = $_account->IdUser; $_folderSync = $_accountNode->GetAttribute('inbox_sync_type', FOLDERSYNC_AllEntireMessages); if ($_newAccount->MailProtocol != MAILPROTOCOL_POP3) { $_folderSync = $_newAccount->GetDefaultFolderSync($_settings); } $_validatedError = $_newAccount->ValidateData(); if (true !== $_validatedError) { CXmlProcessing::PrintErrorAndExit($_validatedError, $_xmlRes); } if ($_user->CreateAccount($_newAccount, $_folderSync)) { if (isset($_SESSION[ACCOUNT_IDS])) { unset($_SESSION[ACCOUNT_IDS]); } CXmlProcessing::GetAccountList($_dbStorage, $_xmlRes, $_account, $_newAccount->Id); } else { CXmlProcessing::PrintErrorAndExit(getGlobalError(), $_xmlRes); } }