'user'), null, array('placeholders' => 'User\\')); protected $_loginPageQuery = array(array('isMainLoginPage' => 'y')); protected $_role = 'user'; protected $_errorMessages = array( self::ERROR_INVALID_CREDENTIALS => 'Invalid Email Address or Password', self::ERROR_NOT_APPROVED => 'Your account is not approved yet', self::ERROR_ACCOUNT_NOT_ACTIVE => 'Your account or company is not active', ); /** * Return auth object * @return \App\User\Auth */ public static function getInstance() { if (null === self::$_instance) { self::$_instance = new self(); } return self::$_instance; } public function getSuMode() { return (bool) $this->getSessionValue('suModeEnabled'); } public function setSuMode($flag = true) { $this->setSessionValue('suModeEnabled', (bool) $flag); } public function initECommerce() { if (Qs_SiteMap::getAliasByItem('ECommerce_Cart_')) { $checkoutView = new CheckoutView(); $checkoutView->unsetUserDataFromSession(); $cartObj = new CartObj(); $cartObj->setPrimaryKey($cartObj->getCartId()); $cartObj->mergeCart(); } return $this; } /** * @param Zend_Auth_Adapter_Interface|Qs_Auth_Adapter_DbTable $adapter * @return Zend_Auth_Result */ public function authenticate(Zend_Auth_Adapter_Interface $adapter) { $result = parent::authenticate($adapter); if ($result->isValid()) { $messages = []; if (null === $this->getData('status')) { $messages = [$this->_errorMessages[self::ERROR_NOT_APPROVED]]; } elseif (Entity::STATUS_ACTIVE != $this->getData('status') || CompanyEntity::STATUS_ACTIVE != $this->getData('companyStatus') ) { $messages = [$this->_errorMessages[self::ERROR_ACCOUNT_NOT_ACTIVE]]; } if ($messages) { $identity = $this->getIdentity(); if (isset($identity['autologinCode'])) { $adapter->clearAutologinCode($identity['autologinCode']); } $this->clearIdentity(); $result = new Zend_Auth_Result(Zend_Auth_Result::FAILURE_UNCATEGORIZED, null, $messages); if (Qs_SiteMap::getAliasByItem('ECommerce_Cart_')) { $cartObj = new CartObj(); $cartObj->clearSessionCartObject(); } foreach (Zend_Session::getIterator() as $namespace) { Zend_Session::namespaceUnset($namespace); } } } else { $code = $result->getCode(); $identity = $result->getIdentity(); $messages = [$this->_errorMessages[self::ERROR_INVALID_CREDENTIALS]]; $result = new Zend_Auth_Result($code, $identity, $messages); } return $result; } public function getLoginUrl() { if (null === $this->_loginUrl) { $url = Qs_SiteMap::findFirst(['xLoginFor' => CURRENT_PAGE], null, null, 'url'); if (!$url) { $parentId = Qs_SiteMap::findFirst(['fullAlias' => CURRENT_PAGE], null, null, 'id'); if ($parentId) { $url = Qs_SiteMap::findFirst( ['idParent' => $parentId], ['type' => 'User\\Login\\'], null, 'url' ); } } if (!$url) { $url = parent::getLoginUrl(); } $this->_loginUrl = $url; } return $this->_loginUrl; } }