/** * * @return string main talbe name */ public function getMainTable() { if (empty($this->_mainTable)) { App_Main::throwException('Empty main table name'); } return $this->_mainTable; }
/** * Validate hash against hashing method (with or without salt) * * @param string $password * @param string $hash * @return bool * @throws Exception */ public function validateHash($password, $hash) { $hashArr = explode(':', $hash); switch (count($hashArr)) { case 1: return $this->hash($password) === $hash; case 2: return $this->hash($hashArr[1] . $password) === $hashArr[0]; } App_Main::throwException('Invalid hash.'); }
protected function _toHtml() { $this->setText(''); foreach ($this->getSortedChildren() as $name) { $block = $this->getLayout()->getBlock($name); if (!$block) { App_Main::throwException('Invalid block: %s', $name); } $this->addText($block->toHtml()); } return parent::_toHtml(); }
/** * Get the Basecamp API connector object * * @return Connect_Basecamp */ public function getBcConnect() { //check for user session if (!($user = App_Main::getSession()->getUser())) { App_Main::throwException('User session not found. Please login to connect'); return; } //check for bc host and bc token in the user object if (!$user->getBcHost() || !$user->getBcAuthToken()) { App_Main::throwException('Unable to connect to BC::unable to find sufficient credentials'); return; } //load the bc connect api object if not loaded already if (!$this->_bcConnect) { $this->_bcConnect = new Connect_Basecamp($user->getBcHost(), $user->getBcAuthToken(), 'X', self::BC_CONNECT_FORMAT); } return $this->_bcConnect; }
/** * Get an instance of the block from the block name * * @param string $block * @param array $attributes * @return Core_Block_Abstract */ protected function _getBlockInstance($block, array $attributes = array()) { $block = App_Main::getBlockInstance($block, $attributes); if (empty($block)) { App_Main::throwException('Invalid block type: %s', $block); } if (!$block instanceof Core_Block_Abstract) { App_Main::throwException('Invalid block type: %s', $block); } return $block; }
protected function applyIPFilter($action) { if ($this->_currentArea != 'frontend' || $this->_disableIPFilter) { return $action; } $countryFilterEnabled = $this->_getWebsite()->getConfig("country_filter_enabled"); $actionList = explode(",", $this->_getWebsite()->getConfig("country_filter_restricted_url_list")); $restricted = false; if ($countryFilterEnabled && (in_array("*", $actionList) || in_array($this->_request->_route, $actionList))) { $location = $this->_getSession()->getRemoteLocationDetails(); if (!$location) { $location = App_Main::getHelper('core/http')->getRemoteLocationDetails(); if (!$location) { // cannot get location - could be due to some error communicating with the location server App_Main::throwException("Could not contact location server."); } $this->_getSession()->setRemoteLocationDetails($location); } $allowList = explode(",", $this->_getWebsite()->getConfig("country_filter_allow_list")); $restricted = count($allowList) > 0 ? true : false; foreach ($allowList as $country) { if ($location->getCountryCode() === $country) { $restricted = false; break; } } foreach (explode(",", $this->_getWebsite()->getConfig("country_filter_deny_list")) as $country) { if ($location->getCountryCode() === $country) { $restricted = true; break; } } } $ipFilterEnabled = $this->_getWebsite()->getConfig("ip_filter_enabled"); if ($ipFilterEnabled) { $allowList = explode(",", $this->_getWebsite()->getConfig("ip_filter_allow_list")); $remoteIP = $this->getRequest()->getServer('REMOTE_ADDR'); foreach ($allowList as $ip) { if ($remoteIP == $ip) { // do wild card match instead $restricted = false; break; } } $denyList = explode(",", $this->_getWebsite()->getConfig("ip_filter_deny_list")); foreach ($denyList as $ip) { if ($remoteIP == $ip) { $restricted = true; break; } } } if ($restricted) { $action = $this->noaccess_action; } return $action; }
/** * Throw exception on an error * * @param string $str * @return bool */ private function throwError($str) { return App_Main::throwException($str); }
/** * Authenticate user name and password and save login record * * @param string $username * @param string $password * @return boolean * @throws Core_Exception */ public function authenticate($username, $password) { $result = false; try { $this->loadByUsername($username); $sensitive = true; if ($sensitive && $this->getId() && App_Main::getHelper('core')->validateHash($password, $this->getPassword())) { if ($this->getIsActive() != '1') { App_Main::throwException('This account is inactive.'); } $result = true; } } catch (Core_Exception $e) { $this->unsetData(); throw $e; } if (!$result) { $this->unsetData(); } return $result; }
public function dispatch() { $this->preDispatch(); $request = $this->getRequest(); $request->setPathInfo()->setDispatched(false); $i = 0; while (!$request->isDispatched() && $i++ < 100) { foreach ($this->_routers as $router) { if ($router->match($this->getRequest())) { break; } } } if ($i > 100) { App_Main::throwException('Front controller reached 100 router match iterations'); } $this->getResponse()->sendResponse(); $this->postDispatch(); return $this; }
/** * Get resource collection instance * * @return Core_Model_Resource_Collection_Abstract */ public function getResourceCollection() { if (empty($this->_resourceCollectionName)) { App_Main::throwException('Model collection resource name is not defined'); } return App_main::getResourceModel($this->_resourceCollectionName, $this->_getResource()); }