_sessionTable) { $this->_sessionTable = new Qs_Db_Table(array('name' => $this->_tableName . 'Session')); } return $this->_sessionTable; } public function clearAutologinCode($code) { if ($code) { $this->getSessionTable()->delete('`' . $this->_autologinColumn. '` = ' . $this->_zendDb->quote($code)); } return $this; } public function clearSession() { $this->getSessionTable()->deleteBy(array('sessionId' => session_id())); return $this; } public function saveAutologinCode($code) { $table = $this->getSessionTable(); $table->deleteBy(array($this->_autologinColumn => $code)); $table->insert(array( 'adminId' => $this->_resultRow['id'], 'sessionId' => session_id(), $this->_autologinColumn => $code )); return $this; } protected function _authenticateCreateSelect() { if (isset($this->_autologinCode)) { $select = clone $this->getDbSelect(); $select->from(array('a' => $this->_tableName), array('*', new Zend_Db_Expr('1 AS `zend_auth_credential_match`'))) ->join(array('as' => $this->_tableName . 'Session'), "`as`.`adminId` = `a`.`id`", array()) ->where($this->_zendDb->quoteIdentifier('as.' . $this->_autologinColumn, true) . ' = ?', $this->_autologinCode) ->limit(1); } else { $select = parent::_authenticateCreateSelect(); } return $select; } public function generateUniqueId() { $key = array( 'adminId' => $this->_resultRow['id'], 'sessionId' => session_id() ); $data = array( 'uniqueId' => uniqid('c', true) ); if (false === $this->getSessionTable()->searchBy($key)) { $this->getSessionTable()->insert(array_merge($key, $data)); } else { $this->getSessionTable()->update( $data, '`adminId` = ' . $this->_zendDb->quote($key['adminId']) . ' ' . 'AND `sessionId` = ' . $this->_zendDb->quote($key['sessionId']) ); } return $data['uniqueId']; } public function autologinByUniqueId($uniqueId) { if (empty($uniqueId)) { return false; } if (false === ($adminId = $this->getSessionTable()->searchBy(compact('uniqueId'), 'adminId'))) { return false; } $autologinCode = md5('autologin' . time() . md5(rand(100, 1000))); $sessionId = session_id(); $this->getSessionTable()->delete( '`adminId` = ' . $this->_zendDb->quote($adminId) . ' ' . 'AND `sessionId` = ' . $this->_zendDb->quote($sessionId) ); $this->getSessionTable()->insert(compact('adminId', 'sessionId', 'autologinCode')); return $autologinCode; } public function removeUniqueId($uniqueId) { $this->getSessionTable()->update(array('uniqueId' => null), '`uniqueId` = ' . $this->_zendDb->quote($uniqueId)); } /** * Regenerates authCode than uses in remote authentication for gmada (using iframe) * @return null|string */ public function regenerateAuthCode() { if (isset($this->_resultRow['id'])) { $authCode = uniqid(); if ($this->getTable()->update(array('authCode' => $authCode), array('id = ?' => $this->_resultRow['id']))) { return $authCode; } } return false; } public function clearAuthCode($primaryKey) { $this->getTable()->update( array('authCode' => null, 'authCodeExpirationDate' => null), array('id = ?' => (int) $primaryKey) ); return $this; } /** * Updates field 'authCodeExpirationDate' on each authentication * @return App_Admin_AuthAdapter */ public function updateCodeExpirationDate() { if (isset($this->_resultRow['id'])) { $expirationTime = strtotime('+' . (int) session_cache_expire() . ' minutes'); $this->getTable()->update( array('authCodeExpirationDate' => date('Y-m-d H:i:s', $expirationTime)), array('id = ?' => $this->_resultRow['id']) ); } return $this; } }