_tableName) { $this->_tableName = Qs_Db::getTableName($this->_tableAlias, $this->getIsService()); } $config = Zend_Registry::get('config')->toArray(); $path = explode('_', get_class($this)); foreach ($path as &$name) { $name = strtolower(substr($name, 0, 1)) . substr($name, 1); } $options = Qs_Array::get($config, $path); if (is_array($options) && !empty($options)) { $this->setOptions($options); } $db = Qs_Db::getInstance(); parent::__construct($db); } public function setOptions($options) { if (isset($options['options'])) { unset($options['options']); } foreach ($options as $name => $value) { $method = 'set' . ucfirst($name); if (method_exists($this, $method)) { $this->$method($value); } } return $this; } public function getIsService() { return $this->_isService; } public function setIsService($flag) { $this->_isService = (bool) $flag; } public function setRemoteAuthEnabled($flag = true) { $this->_remoteAuthEnabled = (bool) $flag; return $this; } public function isRemoteAuthEnabled() { return $this->_remoteAuthEnabled; } public function setRemoteAuthColumn($column) { $this->_remoteAuthColumn = $column; return $this; } public function getRemoteAuthColumn() { return $this->_remoteAuthColumn; } public function setRemoteUserExpiration($date) { if (null === $this->_resultRow) { throw new Qs_Exception('method isRemoteUser mut be called first'); } $sql = 'UPDATE ' . $this->_zendDb->quoteIdentifier($this->_tableName) . ' ' . 'SET remotePasswordExpirationDate = ' . $this->_zendDb->quote($date) . ' ' . 'WHERE id = ' . $this->_zendDb->quote($this->_resultRow['id'], Qs_Db::INT_TYPE) . ' ' . 'LIMIT 1'; $this->_zendDb->query($sql); } public function isRemoteUserPasswordExpired() { if (null === $this->_resultRow) { throw new Qs_Exception('method isRemoteUser mut be called first'); } if (false === ($time = strtotime($this->_resultRow['remotePasswordExpirationDate'])) || $time < time()) { return true; } return false; } public function isRemoteUser() { $select = $this->_zendDb->select(); $select->from($this->_tableName); if (null !== $this->_identity) { $select->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity); } else if (null !== $this->_autologinCode) { $select->where($this->_zendDb->quoteIdentifier($this->_autologinColumn, true) . ' = ?', $this->_autologinCode); } else { throw new Qs_Exception('There is no identity to call isRemoteUser function'); } $select->where($this->_zendDb->quoteIdentifier($this->_remoteAuthColumn, true) . ' = ?', 'y'); $select->limit(1); $this->_resultRow = $this->_zendDb->fetchRow($select); return (is_array($this->_resultRow) && !empty($this->_resultRow)); } public function setIdentity($spec) { if (is_array($spec)) { if (isset($spec['identity'])) { parent::setIdentity($spec['identity']); } if (isset($spec['credential'])) { $this->setCredential($spec['credential']); } if (isset($spec['autologinCode'])) { $this->setAutologinCode($spec['autologinCode']); } } else { parent::setIdentity($spec); } return $this; } public function getIdentity() { return $this->_identity; } public function getCredential() { return $this->_credential; } public function getTable() { if (null === $this->_table) { $this->_table = new Qs_Db_Table(array('name' => $this->_tableName, 'db' => $this->_zendDb)); } return $this->_table; } public function saveAutologinCode($code) { $this->getTable()->updateByKey(array($this->_autologinColumn => $code), $this->_resultRow['id']); return $this; } public function clearAutologinCode($code) { if ($code) { $sql = 'UPDATE ' . $this->_zendDb->quoteIdentifier($this->_tableName) . ' ' . 'SET ' . $this->_autologinColumn. ' = NULL ' . 'WHERE ' . $this->_autologinColumn. ' = ' . $this->_zendDb->quote($code); $this->_zendDb->query($sql); } return $this; } public function setAutologinCode($code) { $this->_autologinCode = $code; } public function getAutologinCode() { return $this->_autologinCode; } public function getAutologinIdentity($code) { if (empty($code)) { return false; } $select = $this->_zendDb->select(); $select->from($this->_tableName) ->where('autologinCode = ?', $code) ->limit(1); if (false !== ($data = $this->_zendDb->fetchRow($select))) { return $data[$this->_identityColumn]; } return false; } protected function _authenticateCreateSelect() { if (isset($this->_autologinCode)) { $select = clone $this->getDbSelect(); $select->from($this->_tableName, array('*', new Zend_Db_Expr('1 AS zend_auth_credential_match'))) ->where($this->_zendDb->quoteIdentifier($this->_autologinColumn, true) . ' = ?', $this->_autologinCode) ->limit(1); } else { $select = parent::_authenticateCreateSelect(); } return $select; } protected function _authenticateSetup() { if (!isset($this->_autologinCode)) { return parent::_authenticateSetup(); } $this->_authenticateResultInfo = array( 'code' => Zend_Auth_Result::FAILURE, 'autologinCode' => $this->_autologinCode, 'messages' => array() ); return true; } }