Commit 75c7f039 authored by Carsten  Rose's avatar Carsten Rose
Browse files

Fixed 'Unknown SIP after login/logout'

Report.php, Store.php, QuickFormQuery.php: configuration option 'SESSION_NAME' removed and hard coded to 'qfq'.
Session.php, Sip.php: function checkFeUserUid() moved from Sip to Session. Will be called by using 'Session'. SIP's now stored one level deeper in $_SESSION['qfq'][...]. This makes it easier to destroy the SIP cachae in case of login/logout. Destroying the whole $_SESSION var is not a good idea.
parent 11e9b770
......@@ -14,6 +14,7 @@ require_once(__DIR__ . '/../../qfq/qfq/exceptions/CodeException.php');
require_once(__DIR__ . '/../../qfq/qfq/exceptions/DbException.php');
class QfqController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
public function showAction() {
try {
......
......@@ -90,8 +90,6 @@ Setup a *report* to manage all *forms*: Create a Typo3 page and insert a content
+------------------------+----------------------------------+----------------------------------------------------------------------------+
| DB_INIT | DB_INIT=set names utf8 | Global init for using the database. |
+------------------------+----------------------------------+----------------------------------------------------------------------------+
| SESSION_NAME | SESSION_NAME=qfq | PHP Session name, by default 'qfq' |
+------------------------+----------------------------------+----------------------------------------------------------------------------+
| SQL_LOG | SQL_LOG=sql.log | Filename to log SQL commands: relative to <ext_dir> or absolute. |
+------------------------+----------------------------------+----------------------------------------------------------------------------+
| SQL_LOG_MODE | SQL_LOG_MODE=modify | *all*: every statement will be logged - this is a lot |
......@@ -117,7 +115,6 @@ Example: *<ext_dir>/config.ini*
DB_NAME = qfq_db
DB_NAME_TEST = qfq_db_test
DB_INIT = set names utf8
SESSION_NAME = qfq
SQL_LOG = sql.log
SHOW_DEBUG_INFO = auto
CSS_LINK_CLASS_INTERNAL = internal
......
......@@ -8,8 +8,6 @@ DB_NAME_TEST = <TESTDB>
DB_INIT = set names utf8
SESSION_NAME = qfq
SQL_LOG = sql.log
; all, modify
SQL_LOG_MODE = modify
......
......@@ -15,6 +15,9 @@ const API_DIR = 'typo3conf/ext/qfq/qfq/api';
const QFQ_LOG = 'qfq.log';
const SESSION_LIFETIME_SECONDS = 86400;
const SESSION_FE_USER_UID = 'fe_user_uid';
const SESSION_NAME = 'qfq';
const FORM_LOAD = 'form_load';
const FORM_SAVE = 'form_save';
......@@ -37,8 +40,6 @@ const F_BS_LABEL_COLUMNS = 'bsLabelColumns';
const F_BS_INPUT_COLUMNS = 'bsInputColumns';
const F_BS_NOTE_COLUMNS = 'bsNoteColumns';
const SESSION_FE_USER_UID = 'fe_user_uid';
const RETURN_URL = 'return_url';
const RETURN_SIP = 'return_sip';
const RETURN_ARRAY = 'return_array';
......@@ -268,7 +269,6 @@ const SYSTEM_DB_PASSWORD = 'DB_PASSWORD';
const SYSTEM_DB_NAME = 'DB_NAME';
const SYSTEM_DB_NAME_TEST = 'DB_NAME_TEST';
const SYSTEM_DB_INIT = 'DB_INIT';
const SYSTEM_SESSION_NAME = 'SESSION_NAME';
const SYSTEM_SQL_LOG = 'SQL_LOG'; // Logging to file
const SYSTEM_SQL_LOG_MODE = 'SQL_LOG_MODE'; // Mode, which statements to log.
const SYSTEM_DATE_FORMAT = 'DATE_FORMAT';
......
......@@ -119,6 +119,11 @@ class QuickFormQuery {
mb_internal_encoding("UTF-8");
// session_name(SESSION_NAME);
// session_start();
$this->session = Session::getInstance($phpUnit);
// session.cache_expire
// session.cookie_lifetime
// session.gc_maxlifetime
......@@ -149,7 +154,6 @@ class QuickFormQuery {
$bodytext = $this->t3data[T3DATA_BODYTEXT];
$this->session = Session::getInstance($phpUnit);
$this->store = Store::getInstance($bodytext, $phpUnit);
$this->store->setVar(TYPO3_TT_CONTENT_UID, $t3data[T3DATA_UID], STORE_TYPO3);
$this->db = new Database();
......@@ -186,6 +190,10 @@ class QuickFormQuery {
if ($class)
$html = Support::wrapTag("<div class='$class'>", $html);
// $feUidLoggedIn = isset($GLOBALS["TSFE"]->fe_user->user["uid"]) ? $GLOBALS["TSFE"]->fe_user->user["uid"] : false;
// $feUidSession = $_SESSION[SESSION_NAME][SESSION_FE_USER_UID];
// $html .= "<p>feUidLoggedIn: $feUidLoggedIn / feUidSession: $feUidSession</p>";
return $html;
}
......@@ -218,6 +226,7 @@ class QuickFormQuery {
if (!$sipFound) {
$this->store->createSipAfterFormLoad($formName);
}
$this->store->fillStoreTableDefaultColumnType($this->formSpec['tableName']);
switch ($this->formSpec['render']) {
......@@ -536,7 +545,7 @@ class QuickFormQuery {
* @return string
*/
private function doReport() {
$report = new Report($this->t3data, $this->store->getVar(SYSTEM_SESSION_NAME, STORE_SYSTEM), $this->eval, $this->phpUnit);
$report = new Report($this->t3data, $this->eval, $this->phpUnit);
$html = $report->process($this->t3data['bodytext']);
......
......@@ -100,17 +100,16 @@ class Report {
* Report constructor.
*
* @param array $t3data
* @param $sessionName
* @param Evaluate $eval
* @param bool $phpUnit
*/
public function __construct(array $t3data, $sessionName, Evaluate $eval, $phpUnit = false) {
public function __construct(array $t3data, Evaluate $eval, $phpUnit = false) {
$this->phpUnit = $phpUnit;
Support::setIfNotSet($t3data, "uid", 0);
$this->sip = new Sip($sessionName, $phpUnit);
$this->sip = new Sip($phpUnit);
if ($phpUnit) {
$this->sip->sipUniqId('badcaffee1234');
}
......
......@@ -24,26 +24,30 @@ class Session {
self::$phpUnit = $phpUnit;
if (self::$phpUnit) {
if (self::$phpUnit === true) {
self::$sessionLocal = array();
} else {
session_name();
session_name(SESSION_NAME);
session_start();
}
self::checkFeUserUid();
}
/**
* @param bool|false $phpUnit
* @return null|\qfq\Store
*
*/
public static function getInstance($phpUnit = false) {
private static function checkFeUserUid() {
// Design Pattern: Singleton
if (self::$instance === null) {
self::$instance = new self($phpUnit);
}
$feUidLoggedIn = isset($GLOBALS["TSFE"]->fe_user->user["uid"]) ? $GLOBALS["TSFE"]->fe_user->user["uid"] : false;
$feUidSession = Session::get(SESSION_FE_USER_UID);
return self::$instance;
if ($feUidLoggedIn !== $feUidSession) {
// destroy existing session store
Session::clear();
// save new feUserUid
Session::set(SESSION_FE_USER_UID, $feUidLoggedIn);
}
}
/**
......@@ -58,8 +62,8 @@ class Session {
else
$value = false;
} else {
if (isset($_SESSION[$key]))
$value = $_SESSION[$key];
if (isset($_SESSION[SESSION_NAME][$key]))
$value = $_SESSION[SESSION_NAME][$key];
else
$value = false;
......@@ -68,6 +72,18 @@ class Session {
return $value;
}
/**
*
*/
public static function clear() {
if (self::$phpUnit) {
self::$sessionLocal = array();
} else {
$_SESSION[SESSION_NAME] = array();
}
}
/**
* @param $key
* @param $value
......@@ -77,19 +93,22 @@ class Session {
if (self::$phpUnit) {
self::$sessionLocal[$key] = $value;
} else {
$_SESSION[$key] = $value;
$_SESSION[SESSION_NAME][$key] = $value;
}
}
/**
* @param bool|false $phpUnit
* @return null|\qfq\Store
*/
public static function clear() {
public static function getInstance($phpUnit = false) {
if (self::$phpUnit) {
self::$sessionLocal = array();
} else {
unset($_SESSION);
// Design Pattern: Singleton
if (self::$instance === null) {
self::$instance = new self($phpUnit);
}
return self::$instance;
}
}
\ No newline at end of file
......@@ -32,7 +32,10 @@ class Sip {
private $phpUnit = false;
private $staticUniqId = false;
function __construct($sessionname, $phpUnit = false) {
/**
* @param bool|false $phpUnit
*/
function __construct($phpUnit = false) {
$this->phpUnit = $phpUnit;
......@@ -48,13 +51,7 @@ class Sip {
// session_start();
// }
$feUserUid = Session::get(SESSION_FE_USER_UID);
// Typo3: remember logged in FE User
if (isset($GLOBALS["TSFE"]->fe_user->user["uid"]) && $feUserUid === false) {
Session::set(SESSION_FE_USER_UID, $GLOBALS["TSFE"]->fe_user->user["uid"]);
}
// $this->checkFeUserUid();
}
/**
......@@ -75,7 +72,7 @@ class Sip {
public function queryStringToSip($queryString, $mode = RETURN_URL, $phpScriptName = INDEX_PHP) {
// Validate: Check if still the same fe_user is logged in.
$this->checkFeUserUid();
// $this->checkFeUserUid();
$clientArray = array();
$sipArray = array();
......@@ -132,22 +129,6 @@ class Sip {
return $rc;
}
/**
*
*/
private function checkFeUserUid() {
// Validate: Check if still the same fe_user is logged in.
if (isset($GLOBALS["TSFE"]->fe_user->user["uid"])) {
$feUserUid = Session::get(SESSION_FE_USER_UID);
if ($feUserUid !== false && $feUserUid != $GLOBALS["TSFE"]->fe_user->user["uid"]) {
Session::clear();
}
}
}
/**
* Splits the $paramArray in &$clientArray and &$sipArray. $sipArray contains all key/values pairs wich are not belong to Typo3.
*
......@@ -257,7 +238,7 @@ class Sip {
}
// Validate: Check if still the same fe_user is logged in.
$this->checkFeUserUid();
// $this->checkFeUserUid();
# Check if index 's' exists.
$sessionVar = Session::get($s);
......
......@@ -290,8 +290,7 @@ class Store {
*/
private static function fillStoreSip() {
$sessionName = self::getVar(SYSTEM_SESSION_NAME, STORE_SYSTEM);
self::$sip = new Sip($sessionName);
self::$sip = new Sip(self::$phpUnit);
$s = self::getVar(CLIENT_SIP, STORE_CLIENT);
if ($s !== false) {
......@@ -494,7 +493,7 @@ class Store {
// Store in SIP Store (cause it's empty until now).
$tmpParam[SIP_SIP] = $sip;
self::setVarArray($tmpParam, STORE_SIP);
self::setVarArray($tmpParam, STORE_SIP, true);
}
......
......@@ -921,7 +921,7 @@ EOF;
$GLOBALS["TSFE"] = new FakeTSFEReport();
$this->eval = new qfq\Evaluate($this->store, $this->db);
$this->report = new qfq\Report(array(), $this->store->getVar(SYSTEM_SESSION_NAME, STORE_SYSTEM), $this->eval, true);
$this->report = new qfq\Report(array(), $this->eval, true);
$this->executeSQLFile(__DIR__ . '/fixtures/Generic.sql', true);
}
......
......@@ -66,14 +66,17 @@ class StoreTest extends \PHPUnit_Framework_TestCase {
public function testSetVarStoreSystem() {
$dbTest = 'crose_qfq_db_phpunit';
// Sessionname: default value
$this->assertEquals('qfq', $this->store->getVar(SYSTEM_SESSION_NAME, STORE_SYSTEM), "System: SESSIONNAME");
$this->assertEquals($dbTest, $this->store->getVar(SYSTEM_DB_NAME, STORE_SYSTEM), "System: DB_NAME");
// set new Sessionname
$this->store->setVar(SYSTEM_SESSION_NAME, "anothersessionname", STORE_SYSTEM);
$this->store->setVar(SYSTEM_DB_NAME, "anothername", STORE_SYSTEM);
$this->assertEquals('anothersessionname', $this->store->getVar(SYSTEM_SESSION_NAME, STORE_SYSTEM), "System: SESSIONNAME");
$this->assertEquals('anothername', $this->store->getVar(SYSTEM_DB_NAME, STORE_SYSTEM), "System: DB_NAME");
// restore for further testing
$this->store->setVar(SYSTEM_DB_NAME, $dbTest, STORE_SYSTEM);
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment