/** * Returns the active virtual session object or null. * * @param string $sessionID * @return \wcf\data\session\virtual\SessionVirtual */ public static function getExistingSession($sessionID) { $sql = "SELECT\t*\n\t\t\tFROM\t" . static::getDatabaseTableName() . "\n\t\t\tWHERE\tsessionID = ?\n\t\t\t\tAND ipAddress = ?\n\t\t\t\tAND userAgent = ?"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($sessionID, UserUtil::getIpAddress(), UserUtil::getUserAgent())); return $statement->fetchObject(__CLASS__); }
/** * Attention: This method does not always return a new object, in case a matching virtual session * already exists, the existing session will be returned rather than a new session being created. * * @see \wcf\data\AbstractDatabaseObjectAction::create() */ public function create() { // try to find an existing virtual session $baseClass = call_user_func(array($this->className, 'getBaseClass')); $virtualSession = call_user_func(array($baseClass, 'getExistingSession'), $this->parameters['data']['sessionID']); if ($virtualSession !== null) { return $virtualSession; } if (!isset($this->parameters['data']['lastActivityTime'])) { $this->parameters['data']['lastActivityTime'] = TIME_NOW; } if (!isset($this->parameters['data']['ipAddress'])) { $this->parameters['data']['ipAddress'] = UserUtil::getIpAddress(); } if (!isset($this->parameters['data']['userAgent'])) { $this->parameters['data']['userAgent'] = UserUtil::getUserAgent(); } return parent::create(); }
/** * Searches for existing session of a search spider. * * @param integer $spiderID * @return \wcf\data\session\Session */ protected function getExistingSpiderSession($spiderID) { $sql = "SELECT\t*\n\t\t\tFROM\twcf" . WCF_N . "_session\n\t\t\tWHERE\tspiderID = ?\n\t\t\t\tAND userID IS NULL"; $statement = WCF::getDB()->prepareStatement($sql); $statement->execute(array($spiderID)); $row = $statement->fetchArray(); if ($row !== false) { // fix session validation $row['ipAddress'] = UserUtil::getIpAddress(); $row['userAgent'] = UserUtil::getUserAgent(); // return session object return new $this->sessionClassName(null, $row); } return null; }
/** * Creates a new session. */ protected function create() { // create new session hash $sessionID = StringUtil::getRandomID(); // get user automatically $this->user = UserAuthenticationFactory::getInstance()->getUserAuthentication()->loginAutomatically(call_user_func(array($this->sessionClassName, 'supportsPersistentLogins'))); // create user if ($this->user === null) { // no valid user found // create guest user $this->user = new User(null); } if ($this->user->userID != 0) { // user is no guest // delete all other sessions of this user call_user_func(array($this->sessionEditorClassName, 'deleteUserSessions'), array($this->user->userID)); } // save session $this->session = call_user_func(array($this->sessionEditorClassName, 'create'), array( 'sessionID' => $sessionID, 'userID' => $this->user->userID, 'ipAddress' => UserUtil::getIpAddress(), 'userAgent' => UserUtil::getUserAgent(), 'lastActivityTime' => TIME_NOW, 'requestURI' => UserUtil::getRequestURI(), 'requestMethod' => (!empty($_SERVER['REQUEST_METHOD']) ? $_SERVER['REQUEST_METHOD'] : '') )); }
/** * @see \wcf\form\IForm::submit() */ public function submit() { parent::submit(); // save authentication failure if (ENABLE_USER_AUTHENTICATION_FAILURE) { if ($this->errorField == 'username' || $this->errorField == 'password') { $action = new UserAuthenticationFailureAction(array(), 'create', array('data' => array('environment' => RequestHandler::getInstance()->isACPRequest() ? 'admin' : 'user', 'userID' => $this->user !== null ? $this->user->userID : null, 'username' => $this->username, 'time' => TIME_NOW, 'ipAddress' => UserUtil::getIpAddress(), 'userAgent' => UserUtil::getUserAgent()))); $action->executeAction(); if ($this->captchaObjectType) { $this->captchaObjectType->getProcessor()->reset(); } } } }