* SessionHandler provides an abstract implementation for session handling.
*
* @author Alexander Ebert
- * @copyright 2001-2011 WoltLab GmbH
+ * @copyright 2001-2012 WoltLab GmbH
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @package com.woltlab.wcf
* @subpackage system.session
/**
* prevents update on shutdown
* @var boolean
- */
+ */
protected $doNotUpdate = false;
/**
* various environment variables
* @var array
- */
+ */
protected $environment = array();
/**
* group data and permissions
* @var array<array>
- */
+ */
protected $groupData = null;
/**
* language id for active user
* @var integer
- */
+ */
protected $languageID = 0;
/**
* language ids for active user
* @var array<integer>
- */
+ */
protected $languageIDs = null;
/**
* session object
* @var wcf\data\acp\session\ACPSession
- */
+ */
protected $session = null;
/**
* session class name
* @var string
- */
+ */
protected $sessionClassName = '';
/**
/**
* user object
* @var wcf\data\user\User
- */
+ */
protected $user = null;
/**
* session variables
* @var array
- */
+ */
protected $variables = null;
/**
* indicates if session variables changed and must be saved upon shutdown
* @var boolean
- */
+ */
protected $variablesChanged = false;
/**
*
* @param string $key
* @return mixed
- */
+ */
public function __get($key) {
if (isset($this->environment[$key])) {
return $this->environment[$key];
*
* @param string $sessionEditorClassName
* @param string $sessionID
- */
+ */
public function load($sessionEditorClassName, $sessionID) {
$this->sessionEditorClassName = $sessionEditorClassName;
$this->sessionClassName = call_user_func(array($sessionEditorClassName, 'getBaseClass'));
/**
* Initializes session system.
- */
+ */
public function initSession() {
// init session environment
$this->loadVariables();
/**
* Enables cookie support.
- */
+ */
public function enableCookies() {
$this->useCookies = true;
}
/**
* Initializes security token.
- */
+ */
protected function initSecurityToken() {
if ($this->getVar('__SECURITY_TOKEN') === null) {
$this->register('__SECURITY_TOKEN', StringUtil::getRandomID());
*
* @param string $key
* @param string $value
- */
+ */
public function register($key, $value) {
$this->variables[$key] = $value;
$this->variablesChanged = true;
* Unsets a session variable.
*
* @param string $key
- */
+ */
public function unregister($key) {
unset($this->variables[$key]);
$this->variablesChanged = true;
/**
* Initializes session variables.
- */
+ */
protected function loadVariables() {
@$this->variables = unserialize($this->session->sessionVariables);
if (!is_array($this->variables)) {
*
* @param string $sessionID
* @return UserSession
- */
+ */
protected function getExistingSession($sessionID) {
$this->session = new $this->sessionClassName($sessionID);
if (!$this->session->sessionID || !$this->validate()) {
/**
* Creates a new session.
- */
+ */
protected function create() {
// create new session hash
$sessionID = StringUtil::getRandomID();
/**
* Loads group data from cache.
- */
+ */
protected function loadGroupData() {
if ($this->groupData !== null) return;
* Returns language ids for active user.
*
* @return array<integer>
- */
+ */
public function getLanguageIDs() {
$this->loadLanguageIDs();
/**
* Loads language ids for active user.
- */
+ */
protected function loadLanguageIDs() {
if ($this->languageIDs !== null) return;
* logged in, after the login his old session is used to store his full data.
*
* @param User $user
- */
+ */
public function changeUser(User $user) {
$sessionTable = call_user_func(array($this->sessionClassName, 'getDatabaseTableName'));
if ($user->userID) {
// user is not a guest, delete all other sessions of this user
- $sql = "SELECT sessionID
- FROM ".$sessionTable."
+ $sql = "DELETE FROM ".$sessionTable."
WHERE sessionID <> ?
AND userID = ?";
$statement = WCF::getDB()->prepareStatement($sql);
$statement->execute(array($this->sessionID, $this->userID));
- $row = $statement->fetchArray();
-
- if ($row) {
- $sql = "DELETE FROM ".$sessionTable."
- WHERE sessionID = ?";
- $statement = WCF::getDB()->prepareStatement($sql);
- $statement->execute(array(
- $row['sessionID']
- ));
- }
}
// update user reference
/**
* Updates user session on shutdown.
- */
+ */
public function update() {
if ($this->doNotUpdate) return;
/**
* Deletes this session and it's related data.
- */
+ */
public function delete() {
// remove session
$sessionEditor = new $this->sessionEditorClassName($this->session);
* Returns currently active language id.
*
* @return integer
- */
+ */
public function getLanguageID() {
return $this->languageID;
}
* Sets the currently active language id.
*
* @param integer $languageID
- */
+ */
public function setLanguageID($languageID) {
$this->languageID = $languageID;
}
* Resets session-specific storage data.
*
* @param array<integer> $userIDs
- */
+ */
public static function resetSessions(array $userIDs = array()) {
if (count($userIDs)) {
UserStorageHandler::getInstance()->reset($userIDs, 'groupIDs', 1);