_tableName) { $this->_tableName = Qs_Db::getTableName($this->_tableAlias); } Qs_Options::setConstructorOptions($this); parent::__construct(Qs_Db::getInstance()); } 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 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(['name' => $this->_tableName, 'db' => $this->_zendDb]); } return $this->_table; } public function saveAutologinCode($code) { $this->getTable()->updateByKey([$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(Qs_Db::getPair($this->_tableAlias), ['*', new Zend_Db_Expr('1 AS `zend_auth_credential_match`')]) ->where($this->_zendDb->quoteIdentifier($this->_autologinColumn, true) . ' = ?', $this->_autologinCode) ->limit(1); } else { // build credential expression if (empty($this->_credentialTreatment) || (strpos($this->_credentialTreatment, '?') === false)) { $this->_credentialTreatment = '?'; } $credentialExpression = new Zend_Db_Expr( '(CASE WHEN ' . $this->_zendDb->quoteInto( $this->_zendDb->quoteIdentifier($this->_credentialColumn, true) . ' = ' . $this->_credentialTreatment, $this->_credential ) . ' THEN 1 ELSE 0 END) AS ' . $this->_zendDb->quoteIdentifier( $this->_zendDb->foldCase('zend_auth_credential_match') ) ); $select = clone $this->getDbSelect(); $select->from(Qs_Db::getPair($this->_tableAlias), ['*', $credentialExpression]); $select->where($this->_zendDb->quoteIdentifier($this->_identityColumn, true) . ' = ?', $this->_identity); } return $select; } protected function _authenticateSetup() { if (!isset($this->_autologinCode)) { return parent::_authenticateSetup(); } $this->_authenticateResultInfo = [ 'code' => Zend_Auth_Result::FAILURE, 'autologinCode' => $this->_autologinCode, 'messages' => [], ]; return true; } }