/** * Validates a username and password * * This method should return true or false depending on if login * succeeded. * * @return bool */ protected function validateUserPass($sUserName, $sPassword) { if (class_exists('CApi') && \CApi::IsValid()) { /* @var $oApiCalendarManager \CApiCalendarManager */ $oApiCalendarManager = \CApi::Manager('calendar'); /* @var $oApiCapabilityManager \CApiCapabilityManager */ $oApiCapabilityManager = \CApi::Manager('capability'); if ($oApiCalendarManager && $oApiCapabilityManager) { $oAccount = \afterlogic\DAV\Utils::GetAccountByLogin($sUserName); if ($oAccount && $oAccount->IsDisabled) { return false; } $bIsOutlookSyncClient = \afterlogic\DAV\Utils::ValidateClient('outlooksync'); $bIsMobileSync = false; $bIsOutlookSync = false; $bIsDemo = false; if ($oAccount) { $bIsMobileSync = $oApiCapabilityManager->IsMobileSyncSupported($oAccount); $bIsOutlookSync = $oApiCapabilityManager->IsOutlookSyncSupported($oAccount); \CApi::Plugin()->RunHook('plugin-is-demo-account', array(&$oAccount, &$bIsDemo)); } if ($oAccount && $oAccount->IncomingMailPassword === $sPassword && ($bIsMobileSync && !$bIsOutlookSyncClient || $bIsOutlookSync && $bIsOutlookSyncClient) || $bIsDemo || $sUserName === $oApiCalendarManager->GetPublicUser()) { \afterlogic\DAV\Utils::CheckPrincipals($sUserName); return true; } } } return false; }
/** * @param CAccount $oAccount */ public function Init($oAccount) { $bResult = false; if ($oAccount) { if (!$this->initialized) { \afterlogic\DAV\Auth\Backend::getInstance()->setCurrentUser($oAccount->Email); \afterlogic\DAV\Utils::CheckPrincipals($oAccount->Email); $this->initialized = true; } $bResult = true; } return $bResult; }
/** * @param CAccount $oAccount */ public function InitByAccount($oAccount) { $bResult = false; if ($oAccount && (!$this->Account || $this->Account->Email !== $oAccount->Email)) { $this->Account = $oAccount; $this->aAddressBooksCache = array(); $this->aContactItemsCache = array(); $this->aGroupItemsCache = array(); $this->ContactsCache = array(); $this->GroupsCache = array(); \afterlogic\DAV\Auth\Backend::getInstance()->setCurrentUser($oAccount->Email); \afterlogic\DAV\Utils::CheckPrincipals($oAccount->Email); $aPrincipalProperties = \afterlogic\DAV\Backend::Principal()->getPrincipalByPath(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $oAccount->Email); if ($aPrincipalProperties) { if (isset($aPrincipalProperties['uri'])) { $this->Principal = $aPrincipalProperties['uri']; } } } if ($this->Account) { $bResult = true; } return $bResult; }
public static function getPrincipalByEmail($sEmail) { $sEmail = trim(str_ireplace("mailto:", "", $sEmail)); $oPrincipalBackend = Backend::Principal(); $mPrincipalPath = $oPrincipalBackend->searchPrincipals(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX, array('{http://sabredav.org/ns}email-address' => $sEmail)); if (is_array($mPrincipalPath) && count($mPrincipalPath) === 0) { \afterlogic\DAV\Utils::CheckPrincipals($sEmail); $mPrincipalPath = $oPrincipalBackend->searchPrincipals(\afterlogic\DAV\Constants::PRINCIPALS_PREFIX, array('{http://sabredav.org/ns}email-address' => $sEmail)); if (is_array($mPrincipalPath) && count($mPrincipalPath) === 0) { throw new \Exception("Unknown email address"); } } $sPrincipal = null; foreach ($mPrincipalPath as $aPrincipal) { if ($aPrincipal === \afterlogic\DAV\Constants::PRINCIPALS_PREFIX . '/' . $sEmail) { $sPrincipal = $aPrincipal; break; } } if (!isset($sPrincipal)) { throw new \Exception("Unknown email address"); } return $oPrincipalBackend->getPrincipalByPath($sPrincipal); }