} } else { printErrorAndExit(CantCreateAccount, $xmlRes); } } elseif ($loginArray[2] == 0) { printErrorAndExit(PROC_CANT_LOG_NONDEF, $xmlRes); } else { $newAccount =& Account::LoadFromDb($loginArray[0]); if (!$newAccount) { printErrorAndExit(getGlobalError(), $xmlRes); } else { $mailIncPass = $xmlPass; if (DEMOACCOUNTALLOW && $email == DEMOACCOUNTEMAIL) { $mailIncPass = DEMOACCOUNTPASS; } if (ConvertUtils::DecodePassword($loginArray[1], $newAccount) == $mailIncPass) { $_SESSION[ACCOUNT_ID] = $loginArray[0]; $_SESSION[USER_ID] = $loginArray[3]; $account =& $newAccount; $fs =& new FileSystem(INI_DIR . '/temp', $account->Email, $account->Id); $attfolder =& new Folder($_SESSION[ACCOUNT_ID], -1, $_SESSION['attachtempdir']); $fs->DeleteDir($attfolder); unset($fs, $attfolder); $_SESSION[SESSION_LANG] = $account->DefaultLanguage; $sendSettingsList = true; } else { $account =& $newAccount; $account->MailIncPassword = $mailIncPass; $newprocessor =& new MailProcessor($account); if ($newprocessor->MailStorage->Connect(true)) { $_SESSION[ACCOUNT_ID] = $loginArray[0];
/** * @param string $email * @param string $login * @param int $startPage * @param string $password optional * @return bool */ function UserLoginByEmail($email, $login, $startPage = START_PAGE_IS_MAILBOX, $password = null, $toEmail = null, $separated = false) { $newAccount = new Account(); $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { $this->SetError(PROC_CANT_GET_SETTINGS); return false; } $url = 'webmail.php?check=1'; switch ($startPage) { default: $url .= '&start=' . START_PAGE_IS_MAILBOX; break; case START_PAGE_IS_NEW_MESSAGE: $url .= '&start=' . START_PAGE_IS_NEW_MESSAGE; if ($toEmail && strlen($toEmail) > 0) { $url .= '&to=' . $toEmail; } break; case START_PAGE_IS_MAILBOX: case START_PAGE_IS_SETTINGS: case START_PAGE_IS_CONTACTS: $url .= '&start=' . $startPage; break; case START_PAGE_IS_CALENDAR: if ($separated) { $url = 'calendar.php'; } else { $url .= '&start=' . $startPage; } break; } $loginArray =& Account::LoadFromDbByLogin($email, $login); if ($loginArray != null) { if ($loginArray[2] == '1') { if ($password === null) { $this->SetLoginInfo($loginArray[0], $loginArray[3], null, $separated); $this->ChangeLocation($url); return true; } else { if ($password == ConvertUtils::DecodePassword($loginArray[1], $newAccount)) { $this->SetLoginInfo($loginArray[0], $loginArray[3], null, $separated); $this->ChangeLocation($url); return true; } else { $account =& Account::LoadFromDb($loginArray[0]); $account->MailIncPassword = $password; $newprocessor = new MailProcessor($account); if ($newprocessor->MailStorage->Connect(true)) { if ($account->Update()) { $this->SetLoginInfo($account->Id, $account->IdUser, $account->DefaultLanguage, $separated); $this->ChangeLocation($url); return true; } else { $this->SetError(getGlobalError()); } } else { $this->SetError(PROC_WRONG_ACCT_PWD); } } } } else { $this->SetError(PROC_CANT_LOG_NONDEF); } } else { $this->SetError(ErrorPOP3IMAP4Auth); } return false; }
/** * @param string $email * @param string $login * @return Account */ function &SelectAccountFullDataByLogin($email, $login) { $null = null; if (!$this->_dbConnection->Execute($this->_commandCreator->SelectAccountFullDataByLogin($email, $login))) { return $null; } $account = new Account(); $row = $this->_dbConnection->GetNextRecord(); if ($row) { $account->Id = (int) $row->id_acct; $account->IdUser = (int) $row->id_user; $account->IdDomain = (int) $row->id_domain; $account->DefaultAccount = (bool) $row->def_acct; $account->Deleted = (bool) $row->deleted; $account->Email = $row->email; $account->MailProtocol = (int) $row->mail_protocol; $account->MailIncHost = $row->mail_inc_host; $account->MailIncLogin = $row->mail_inc_login; $account->MailIncPort = (int) $row->mail_inc_port; $account->MailOutHost = $row->mail_out_host; $account->MailOutLogin = $row->mail_out_login; $account->MailOutPort = (int) $row->mail_out_port; $account->MailOutAuthentication = (int) $row->mail_out_auth; $account->FriendlyName = $row->friendly_nm; $account->UseFriendlyName = (bool) $row->use_friendly_nm; $account->DefaultOrder = (int) $row->def_order; $account->GetMailAtLogin = (bool) $row->getmail_at_login; $account->MailMode = (int) $row->mail_mode; $account->MailsOnServerDays = (int) $row->mails_on_server_days; $account->SignatureType = (int) $row->signature_type; $account->SignatureOptions = (int) $row->signature_opt; $account->HideContacts = (bool) $row->hide_contacts; $account->MailsPerPage = (int) $row->msgs_per_page; $account->Delimiter = $row->delimiter; $account->NameSpace = $row->personal_namespace; $account->WhiteListing = (bool) $row->white_listing; $account->XSpam = (bool) $row->x_spam; $account->LastLogin = (int) $row->last_login; $account->LoginsCount = (int) $row->logins_count; $account->DefaultSkin = $row->def_skin; $account->DefaultLanguage = $row->def_lang; $account->DefaultIncCharset = ConvertUtils::GetCodePageName((int) $row->def_charset_inc); $account->DefaultOutCharset = ConvertUtils::GetCodePageName((int) $row->def_charset_out); $account->DefaultTimeZone = (int) $row->def_timezone; $account->DefaultDateFormat = $row->def_date_fmt; $account->HideFolders = (bool) $row->hide_folders; $account->MailboxLimit = GetGoodBigInt($row->mailbox_limit); $account->MailboxSize = GetGoodBigInt($row->mailbox_size); $account->AllowChangeSettings = (bool) $row->allow_change_settings; $account->AllowDhtmlEditor = (bool) $row->allow_dhtml_editor; $account->AllowDirectMode = (bool) $row->allow_direct_mode; $account->DbCharset = ConvertUtils::GetCodePageName((int) $row->db_charset); $account->HorizResizer = (int) $row->horiz_resizer; $account->VertResizer = (int) $row->vert_resizer; $account->Mark = (int) $row->mark; $account->Reply = (int) $row->reply; $account->ContactsPerPage = (int) $row->contacts_per_page; $account->ViewMode = (int) $row->view_mode; $account->ImapQuota = (int) $row->imap_quota; $account->MailIncPassword = ConvertUtils::DecodePassword($row->mail_inc_pass, $account); $account->MailOutPassword = ConvertUtils::DecodePassword($row->mail_out_pass, $account); $this->_dbConnection->FreeResult(); } else { $account = $null; } if (!is_object($account) || !$this->_dbConnection->Execute($this->_commandCreator->SelectSignature($account->Id))) { return $null; } $row = $this->_dbConnection->GetNextRecord(); if ($row) { $account->Signature = $row->signature; $this->_dbConnection->FreeResult(); } return $account; }
/** * @param Settings $_settings * @param MySqlStorage $_dbStorage * @param CWebMailLoginInfo $loginInfo * @param Account $refAccount * @param string $errorString */ function Init(&$_settings, &$_dbStorage, &$loginInfo, &$refAccount, &$errorString) { $accountCustomValues = array(); $_log =& CLog::CreateInstance(); $_isNoLoginField = false; $_sendSettingsList = false; /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginInfoBeforeInit', array(&$loginInfo)); $_infoEmail = trim($loginInfo->getEmail()); $_infoLogin = trim($loginInfo->getLogin()); $_infoPassword = $loginInfo->getPassword(); $_infoAdvancedLogin = $loginInfo->getAdvancedLogin(); $_infoLang = trim($loginInfo->getLanguage()); $_domain = $loginInfo->getDomainsSelectValue(); $_email = $_login = $_optLogin = ''; if ($_infoAdvancedLogin && $_settings->AllowAdvancedLogin) { $_email = $_infoEmail; $_login = $_infoLogin; } else { switch ($_settings->HideLoginMode) { case 0: $_email = $_infoEmail; $_login = $_infoLogin; break; case 10: $_email = $_infoEmail; $_isNoLoginField = true; $_emailAddress = new EmailAddress(); $_emailAddress->SetAsString($_email); $_optLogin = $_emailAddress->GetAccountName(); break; case 11: $_email = $_infoEmail; $_isNoLoginField = true; $_optLogin = $_email; break; case 20: case 21: $_login = $_infoLogin; $loginArray = ConvertUtils::ParseEmail($_login); if (20 == $_settings->HideLoginMode) { if (is_array($loginArray) && 2 === count($loginArray)) { $_email = $_login; } else { $_email = $_login . '@'; $_email .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional; } } else { $_email = is_array($loginArray) && 2 === count($loginArray) ? $loginArray[0] . '@' : $_login . '@'; $_email .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional; } break; case 22: case 23: $loginArray = ConvertUtils::ParseEmail($_infoLogin); $_login = is_array($loginArray) && isset($loginArray[0]) ? $loginArray[0] . '@' : $_infoLogin . '@'; $_login .= $_domain && $_settings->UseMultipleDomainsSelection ? $_domain : $_settings->DefaultDomainOptional; $_email = $_login; } } /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginDuringInit', array(&$_login, &$_email)); $bReturn = true; wm_Custom::StaticUseMethod('LdapCustomLoginFunction', array(&$_login, &$_email, &$_infoPassword, &$accountCustomValues, &$errorString, &$bReturn)); if (!$bReturn) { return false; } $_loginArray = null; if (USE_DB) { if ($_isNoLoginField) { $_loginArray =& Account::LoadFromDbOnlyByEmail($_email); if (is_array($_loginArray) && count($_loginArray) > 3) { $_eAccount =& Account::LoadFromDb((int) $_loginArray[0]); if ($_eAccount) { if ($_loginArray[5]) { $errorString = 'Your account is inactive, please contact the system administrator on this.'; return false; } $_login = ConvertUtils::DecodePassword($_loginArray[1], $_eAccount) == $_infoPassword ? $_loginArray[4] : $_optLogin; } else { $_login = $_optLogin; } } else { $_login = $_optLogin; } /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginInfoAfterInit', array(&$_login, &$_email)); } else { /* custom class */ wm_Custom::StaticUseMethod('ChangeLoginInfoAfterInit', array(&$_login, &$_email)); $_loginArray =& Account::LoadFromDbByLogin($_email, $_login); if ($_loginArray[4]) { $errorString = 'Your account is inactive, please contact the system administrator on this.'; return false; } } } if (!$_dbStorage || !$_dbStorage->Connect()) { $_sendSettingsList = false; $errorString = getGlobalError(); return false; } if ($_loginArray === false) { $errorString = getGlobalError(); return false; } else { if ($_loginArray === null) { if ($_settings->AllowNewUsersRegister) { if (!NumOLCallBackFunction($_settings, $_dbStorage, $errorString)) { return false; } $_account = new Account(); $_account->DefaultAccount = true; $_account->Email = $_email; $_account->MailIncLogin = $_login; $_account->MailIncPassword = $_infoPassword; if (strlen($_infoLang) > 0) { $_account->DefaultLanguage = $_infoLang; } $_account->CustomValues = $accountCustomValues; if ($_infoAdvancedLogin && $_settings->AllowAdvancedLogin) { $_account->MailProtocol = $loginInfo->getMailProtocol(); $_account->MailIncPort = $loginInfo->getMailIncPort(); $_account->MailOutPort = $loginInfo->getMailOutPort(); $_account->MailOutAuthentication = $loginInfo->getMailOutAuth(); $_account->MailIncHost = $loginInfo->getMailIncHost(); $_account->MailOutHost = $loginInfo->getMailOutHost(); } else { $_account->MailProtocol = (int) $_settings->IncomingMailProtocol; $_account->MailIncPort = (int) $_settings->IncomingMailPort; $_account->MailOutPort = (int) $_settings->OutgoingMailPort; $_account->MailOutAuthentication = (bool) $_settings->ReqSmtpAuth; $_account->MailIncHost = $_settings->IncomingMailServer; $_account->MailOutHost = $_settings->OutgoingMailServer; } if (DEMOACCOUNTALLOW && $_email == DEMOACCOUNTEMAIL) { $_account->MailIncPassword = DEMOACCOUNTPASS; } /* custom class */ wm_Custom::StaticUseMethod('InitLdapSettingsAccountOnLogin', array(&$_account)); if (0 < strlen($_infoLang)) { $_account->DefaultLanguage = $_infoLang; } /* custom class */ wm_Custom::StaticUseMethod('ChangeAccountBeforeCreateOnLogin', array(&$_account)); if (USE_DB) { $_domain =& $_dbStorage->SelectDomainByName(EmailAddress::GetDomainFromEmail($_account->Email)); if (null !== $_domain) { $_domain->UpdateAccount($_account, $_settings); } } $_validate = $_account->ValidateData(); if ($_validate !== true) { $errorString = $_validate; return false; } else { if ($_account->IsInternal) { $errorString = ErrorPOP3IMAP4Auth; $_log->WriteLine('LOGIN Error: IsInternal = true', LOG_LEVEL_WARNING); return false; } $_processor = new MailProcessor($_account); if ($_processor->MailStorage->Connect(true)) { $_user =& User::CreateUser($_account); if ($_user && $_account) { if (!USE_DB) { $_account->Id = 1; } $_account->IdUser = $_user->Id; } $_inboxSyncType = $_account->GetDefaultFolderSync($_settings); if ($_user != null && $_user->CreateAccount($_account, $_inboxSyncType, false, $_processor->MailStorage)) { if ($_settings->EnableMobileSync && function_exists('mcrypt_encrypt')) { // create Funambol user for loginable user require_once WM_ROOTPATH . 'common/class_funambol_sync_users.php'; $fnSyncUsers = new FunambolSyncUsers($_account); $fnSyncUsers->PerformSync(); } $_SESSION[ACCOUNT_ID] = $_account->Id; $_SESSION[USER_ID] = $_account->IdUser; $_SESSION[SESSION_LANG] = $_account->DefaultLanguage; $_sendSettingsList = true; if (!USE_DB) { Account::SaveInSession($_account); } $_log->WriteEvent('User login', $_account); self::AfterLoginAction($_account, $_processor, $_settings); } else { if ($_user) { User::DeleteUserSettings($_user->Id); } $_error = getGlobalError(); $_error = strlen($_error) > 0 ? $_error : CantCreateUser; $errorString = $_error; return false; } } else { $errorString = getGlobalError(); return false; } } } else { $_log->WriteLine('LOGIN Error: AllowNewUsersRegister = false', LOG_LEVEL_WARNING); $errorString = ErrorPOP3IMAP4Auth; return false; } } else { if ($_loginArray[2] == 0) { $errorString = PROC_CANT_LOG_NONDEF; return false; } else { if (USE_DB) { $_newAccount =& Account::LoadFromDb($_loginArray[0]); if (!$_newAccount) { $errorString = getGlobalError(); return false; } else { $_deleted = $_dbStorage->GetAUserDeleted($_newAccount->IdUser); if (false === $_deleted) { $errorString = getGlobalError(); return false; } else { if (1 === $_deleted) { $errorString = ErrorMaximumUsersLicenseIsExceeded; return false; } } $_mailIncPass = $_infoPassword; if (DEMOACCOUNTALLOW && $_email == DEMOACCOUNTEMAIL) { $_mailIncPass = DEMOACCOUNTPASS; } $_useLangUpdate = false; if (strlen($_infoLang) > 0 && $_newAccount->DefaultLanguage != $_infoLang) { $_newAccount->DefaultLanguage = $_infoLang; $_useLangUpdate = true; } $_account = null; $bIsPasswordCorrect = ConvertUtils::DecodePassword($_loginArray[1], $_newAccount) == $_mailIncPass; $_account =& $_newAccount; $_account->MailIncPassword = $_mailIncPass; $_newprocessor = new MailProcessor($_account); if ($_newprocessor->MailStorage->Connect(true)) { if (!$bIsPasswordCorrect && !$_account->Update()) { return ErrorPOP3IMAP4Auth; } $_SESSION[ACCOUNT_ID] = $_account->Id; $_SESSION[USER_ID] = $_account->IdUser; $_SESSION[SESSION_LANG] = $_account->DefaultLanguage; $tempFiles =& CTempFiles::CreateInstance($_account); $tempFiles->ClearAccount(); unset($tempFiles); $_sendSettingsList = true; $_log->WriteEvent('User login', $_account); if ($_account->MailProtocol == MAILPROTOCOL_IMAP4 && $_account->ImapQuota === 1) { $quota = $_newprocessor->GetQuota(); if ($quota !== false && $quota !== $_account->MailboxLimit) { $_account->MailboxLimit = GetGoodBigInt($quota); $_account->UpdateMailBoxLimit(); } } self::AfterLoginAction($_account, $_newprocessor, $_settings); } else { $errorString = ErrorPOP3IMAP4Auth; return false; } } } } } } if ($_sendSettingsList && USE_DB) { if (!$_dbStorage->UpdateLastLoginAndLoginsCount($_account->IdUser)) { $_sendSettingsList = false; $errorString = getGlobalError(); return false; } } if (isset($_account)) { $refAccount = $_account; } return true; }
/** * @param string $email * @param string $login * @param string $password = null * @return bool */ protected function _UserLoginByEmail($email, $login, $password = null) { require_once WM_ROOTPATH . 'common/class_account.php'; require_once WM_ROOTPATH . 'common/class_dbstorage.php'; require_once WM_ROOTPATH . 'common/class_mailprocessor.php'; $newAccount = new Account(); $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { throw new WebMailModelException('settings error'); } if (!$settings->IncludeLang()) { throw new WebMailModelException('lang error'); } $loginArray =& Account::LoadFromDbByLogin($email, $login); if ($loginArray != null) { if ($loginArray[2] == '1') { if ($password === null) { @session_write_close(); @session_name('PHPWEBMAILSESSID'); @session_start(); $_SESSION[ACCOUNT_ID] = $loginArray[0]; $_SESSION[USER_ID] = $loginArray[3]; return true; } else { if ($password == ConvertUtils::DecodePassword($loginArray[1], $newAccount)) { @session_write_close(); @session_name('PHPWEBMAILSESSID'); @session_start(); $_SESSION[ACCOUNT_ID] = $loginArray[0]; $_SESSION[USER_ID] = $loginArray[3]; return true; } else { $account =& Account::LoadFromDb($loginArray[0]); $account->MailIncPassword = $password; $newprocessor = new MailProcessor($account); if ($newprocessor->MailStorage->Connect(true)) { if ($account->Update()) { @session_write_close(); @session_name('PHPWEBMAILSESSID'); @session_start(); $_SESSION[ACCOUNT_ID] = $account->Id; $_SESSION[USER_ID] = $account->IdUser; $_SESSION[SESSION_LANG] = $account->DefaultLanguage; return true; } else { throw new WebMailModelException(getGlobalError()); } } else { throw new WebMailModelException(ErrorPOP3IMAP4Auth); } } } } else { throw new WebMailModelException(PROC_CANT_LOG_NONDEF); } } else { throw new WebMailModelException(ErrorPOP3IMAP4Auth); } }
/** * @param string $email * @param string $login * @param int $startPage * @param string $password optional * @return bool */ function UserLoginByEmail($email, $login, $startPage = START_PAGE_IS_MAILBOX, $password = null, $toEmail = null) { $newAccount = new Account(); $settings =& Settings::CreateInstance(); if (!$settings || !$settings->isLoad) { $this->SetError(PROC_CANT_GET_SETTINGS); return false; } $getTemp = ''; switch ($startPage) { default: $getTemp = '&start=' . START_PAGE_IS_MAILBOX; break; case START_PAGE_IS_NEW_MESSAGE: if ($toEmail && strlen($toEmail) > 0) { $getTemp = '&start=' . START_PAGE_IS_NEW_MESSAGE . '&to=' . $toEmail; } else { $getTemp = '&start=' . START_PAGE_IS_NEW_MESSAGE; } break; case START_PAGE_IS_MAILBOX: case START_PAGE_IS_SETTINGS: case START_PAGE_IS_CONTACTS: case START_PAGE_IS_CALENDAR: $getTemp = '&start=' . $startPage; break; } $loginArray =& Account::LoadFromDbByLogin($email, $login); if ($loginArray != null) { if ($loginArray[2] == '1') { if ($password == null) { $_SESSION[ACCOUNT_ID] = $loginArray[0]; $_SESSION[USER_ID] = $loginArray[3]; $this->ChangeLocation($settings, $getTemp); return true; } else { if ($password == ConvertUtils::DecodePassword($loginArray[1], $newAccount)) { $_SESSION[ACCOUNT_ID] = $loginArray[0]; $_SESSION[USER_ID] = $loginArray[3]; $this->ChangeLocation($settings, $getTemp); return true; } else { $account =& Account::LoadFromDb($loginArray[0]); $account->MailIncPassword = $password; $newprocessor =& new MailProcessor($account); if ($newprocessor->MailStorage->Connect()) { $_SESSION['id_account'] = $loginArray[0]; $_SESSION[SESSION_LANG] = $account->DefaultLanguage; if ($account->Update()) { $this->ChangeLocation($settings, $getTemp); return true; } else { $this->SetError(getGlobalError()); return false; } } else { $this->SetError(PROC_WRONG_ACCT_PWD); return false; } } } } else { $this->SetError(PROC_CANT_LOG_NONDEF); return false; } } if ($this->_errorMessage == '') { $this->SetError(); } return false; }