Exemple #1
0
 /**
  * @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 DoRegistration()
 {
     $_dbStorage = $_settings = $_xmlObj = $_xmlRes = $_accountId = null;
     $this->_initFuncArgs($_dbStorage, $_settings, $_xmlObj, $_xmlRes, $_accountId);
     $isGdSupport = @function_exists('imagecreatefrompng');
     $captcha = $_xmlObj->GetParamTagValueByName('captcha');
     if ($isGdSupport && (!isset($_SESSION['captcha_keystring']) || $captcha != $_SESSION['captcha_keystring'])) {
         CXmlProcessing::PrintErrorAndExit(CaptchaError, $_xmlRes);
     }
     if (true) {
         $_login = trim($_xmlObj->GetParamTagValueByName('login'));
         $_domainName = trim($_xmlObj->GetParamTagValueByName('domain'));
         $_domain =& $_dbStorage->SelectDomainByName($_domainName);
         if (!$_domain) {
             CXmlProcessing::PrintErrorAndExit(RegDomainNotExist, $_xmlRes);
         }
         $_email = $_login . '@' . $_domainName;
         $_loginArray =& Account::LoadFromDbOnlyByEmail($_email);
         if (is_array($_loginArray) && count($_loginArray) > 3) {
             CXmlProcessing::PrintErrorAndExit(RegAccountExist, $_xmlRes);
         }
         $_password = trim($_xmlObj->GetParamTagValueByName('pass'));
         $_lang = trim($_xmlObj->GetParamTagValueByName('lang'));
         $_timezone = trim($_xmlObj->GetParamTagValueByName('timezone'));
         $_account = new Account();
         $_account->DefaultAccount = true;
         $_account->Email = $_email;
         $_account->MailIncLogin = $_email;
         $_account->MailIncPassword = $_password;
         $_account->DefaultLanguage = $_lang;
         $_account->DefaultTimeZone = $_timezone;
         $_account->FriendlyName = trim($_xmlObj->GetParamTagValueByName('name'));
         $_account->Delimiter = '.';
         $_account->Question1 = trim($_xmlObj->GetParamTagValueByName('question_1'));
         $_account->Answer1 = trim($_xmlObj->GetParamTagValueByName('answer_1'));
         $_account->Question2 = trim($_xmlObj->GetParamTagValueByName('question_2'));
         $_account->Answer2 = trim($_xmlObj->GetParamTagValueByName('answer_2'));
         $_domain->UpdateAccount($_account, $_settings);
         $_validate = $_account->ValidateData();
         if ($_validate !== true) {
             CXmlProcessing::PrintErrorAndExit($_validate, $_xmlRes);
         } else {
             if ($_account->IsInternal) {
                 require_once WM_ROOTPATH . 'common/class_exim.php';
                 if (!CExim::CreateUserShell($_login, $_domainName, $_account->MailboxLimit)) {
                     CXmlProcessing::PrintErrorAndExit(CantCreateUser, $_xmlRes);
                 }
                 $_dbStorage->InsertAccountData($_account);
             }
             $_processor = new MailProcessor($_account);
             if ($_processor->MailStorage->Connect(true)) {
                 $_user =& User::CreateUser($_account);
                 if ($_user && $_account) {
                     $_account->IdUser = $_user->Id;
                 }
                 $_inboxSyncType = $_account->GetDefaultFolderSync($_settings);
                 if ($_user != null && $_user->CreateAccount($_account, $_inboxSyncType, false, $_processor->MailStorage)) {
                     $_SESSION[ACCOUNT_ID] = $_account->Id;
                     $_SESSION[USER_ID] = $_account->IdUser;
                     $_SESSION[SESSION_LANG] = $_account->DefaultLanguage;
                 } else {
                     if ($_user) {
                         User::DeleteUserSettings($_user->Id);
                     }
                     $_error = getGlobalError();
                     $_error = strlen($_error) > 0 ? $_error : CantCreateUser;
                     CXmlProcessing::PrintErrorAndExit($_error, $_xmlRes);
                 }
             } else {
                 if ($_account->IsInternal) {
                     $_dbStorage->DeleteOnlyAccountData($_account->Id);
                     CExim::DeleteUserShell($_login, $_domainName);
                 }
                 CXmlProcessing::PrintErrorAndExit(getGlobalError(), $_xmlRes);
             }
         }
         $_regNode = new XmlDomNode('registration');
         if ($_xmlObj->GetParamValueByName('sign_me') && $_account) {
             $_regNode->AppendAttribute('id_acct', $_account->Id);
             $_regNode->AppendChild(new XmlDomNode('hash', md5(ConvertUtils::EncodePassword($_account->MailIncPassword, $_account)), true));
         }
         $_xmlRes->XmlRoot->AppendChild($_regNode);
     } else {
         CXmlProcessing::PrintErrorAndExit('error', $_xmlRes);
     }
 }