Commit 55d50e6c authored by Carsten  Rose's avatar Carsten Rose
Browse files

#2046: Dynamic Update mit {{feUser:T0}} Feld - fixed. Background: T3...

#2046: Dynamic Update mit {{feUser:T0}} Feld - fixed. Background: T3 environment not available during dynamicUpdate (called by AJAX through API). Restore feUser and feUserUid from Session. Not good, but better than nothing. Still missing: the rest of STORE_TYPO3
Session.php: extend checkFeUserUid() to save feUser as well as feUserUid. Fixed error that getSession() in phpDoc stated it returned class Store - correct is class Session.
Store.php: fillStoreTypo3() now respects that if there is no  T3 environment, restore at least feUser and feUserUid.
parent 890bcd19
......@@ -16,6 +16,7 @@ const QFQ_LOG = 'qfq.log';
const SESSION_LIFETIME_SECONDS = 86400;
const SESSION_FE_USER_UID = 'fe_user_uid';
const SESSION_FE_USER = 'fe_user';
const SESSION_NAME = 'qfq';
......
......@@ -10,6 +10,7 @@ namespace qfq;
class Session {
private static $instance = null;
private static $phpUnit = null;
private static $sessionLocal = array();
......@@ -34,26 +35,35 @@ class Session {
}
/**
*
* Check if the feUserUid is stored in the session (even with 'false' which indicates not logged in user).
* If not, clear the session and save the feUser, feUserUid in the session.
* Check if the recent logged in feUserUid is equal to the one stored in session: If different, invalidate (clear) the session and
* save the new feUser, feUserUid in the session.
* If isset($GLOBALS["TSFE"]), than we're in a T3 environment, else we are called as API classes and need to fake
* feUser / feUserUid from previous stored session.
* It's neccessary to have feUser / feUserUid available in API classes, due to dynamic update which might reload data based on feUser / feUserUid.
*/
private static function checkFeUserUid() {
$feUidSession = Session::get(SESSION_FE_USER_UID);
$feUserUidSession = Session::get(SESSION_FE_USER_UID);
$feUserSession = Session::get(SESSION_FE_USER);
if (isset($GLOBALS["TSFE"])) {
// if noone is logged in: 0
$feUidLoggedIn = isset($GLOBALS["TSFE"]->fe_user->user["uid"]) ? $GLOBALS["TSFE"]->fe_user->user["uid"] : false;
$feUserSession = isset($GLOBALS["TSFE"]->fe_user->user["username"]) ? $GLOBALS["TSFE"]->fe_user->user["username"] : false;
} else {
// If we are called through API there is no T3 FE User logged in. Fake this test.
$feUidLoggedIn = $feUidSession;
// If we are called through API there is no T3 environment. Assume nothing has changed, and fake the following check to always 'no change'.
$feUidLoggedIn = $feUserUidSession;
}
if ($feUidLoggedIn !== $feUidSession) {
if ($feUidLoggedIn !== $feUserUidSession) {
// destroy existing session store
Session::clear();
// save new feUserUid
// save new feUserUid, feUserName
Session::set(SESSION_FE_USER_UID, $feUidLoggedIn);
Session::set(SESSION_FE_USER, $feUserSession);
}
}
......@@ -106,7 +116,7 @@ class Session {
/**
* @param bool|false $phpUnit
* @return null|\qfq\Store
* @return Session class
*/
public static function getInstance($phpUnit = false) {
......
......@@ -17,6 +17,7 @@ require_once(__DIR__ . '/../../qfq/helper/KeyValueStringParser.php');
require_once(__DIR__ . '/../../qfq/helper/Sanitize.php');
require_once(__DIR__ . '/../../qfq/Constants.php');
require_once(__DIR__ . '/../../qfq/store/Sip.php');
require_once(__DIR__ . '/../../qfq/store/Session.php');
require_once(__DIR__ . '/../../qfq/Database.php');
......@@ -45,6 +46,11 @@ class Store {
*/
private static $sip = null;
/**
* @var Session Instance of class Session
*/
private static $session = null;
/**
* @var array Stores all indiviudal stores with the variable raw values
*
......@@ -73,11 +79,14 @@ class Store {
private static $phpUnit = false;
/**
* @param string $bodytext
*/
private function __construct($bodytext = '') {
self::$session = Session::getInstance(self::$phpUnit);
self::$sanitizeClass = [
// TYPO3_DEBUG_LOAD => SANITIZE_ALLOW_DIGIT,
// TYPO3_DEBUG_SAVE => SANITIZE_ALLOW_DIGIT,
......@@ -153,6 +162,8 @@ class Store {
self::fillStoreClient();
self::fillStoreSip();
self::fillStoreExtra();
}
/**
......@@ -237,33 +248,56 @@ class Store {
}
/**
* Copy the BodyText as well as some T3 specific vars to STORE_TYPO3.
* Attention: if called through API, there is no T3 environment. The only values which are available are fe_user and fe_user_uid.
*
* @param $bodytext
* @throws CodeException
*/
private static function fillStoreTypo3($bodytext) {
// form=, showDebugBodyText=, 10.20..
$arr = KeyValueStringParser::parse($bodytext, "=", "\n");
if (isset($GLOBALS["TSFE"]->fe_user->user["username"]))
$arr[TYPO3_FE_USER] = $GLOBALS["TSFE"]->fe_user->user["username"];
if (isset($GLOBALS["TSFE"])) {
if (isset($GLOBALS["TSFE"]->fe_user->user["username"])) {
$arr[TYPO3_FE_USER] = $GLOBALS["TSFE"]->fe_user->user["username"];
}
if (isset($GLOBALS["TSFE"]->fe_user->user["uid"]))
$arr[TYPO3_FE_USER_UID] = $GLOBALS["TSFE"]->fe_user->user["uid"];
if (isset($GLOBALS["TSFE"]->fe_user->user["uid"])) {
$feUid = $GLOBALS["TSFE"]->fe_user->user["uid"];
$arr[TYPO3_FE_USER_UID] = $GLOBALS["TSFE"]->fe_user->user["uid"];
}
if (isset($GLOBALS["TSFE"]->fe_user->user["usergroup"]))
$arr[TYPO3_FE_USER_GROUP] = $GLOBALS["TSFE"]->fe_user->user["usergroup"];
if (isset($GLOBALS["TSFE"]->fe_user->user["usergroup"])) {
$arr[TYPO3_FE_USER_GROUP] = $GLOBALS["TSFE"]->fe_user->user["usergroup"];
}
if (isset($GLOBALS["TSFE"]->page["uid"]))
$arr[TYPO3_TT_CONTENT_UID] = $GLOBALS["TSFE"]->page["uid"];
if (isset($GLOBALS["TSFE"]->page["uid"])) {
$arr[TYPO3_TT_CONTENT_UID] = $GLOBALS["TSFE"]->page["uid"];
}
if (isset($GLOBALS["TSFE"]->id))
$arr[TYPO3_PAGE_ID] = $GLOBALS["TSFE"]->id;
if (isset($GLOBALS["TSFE"]->id)) {
$arr[TYPO3_PAGE_ID] = $GLOBALS["TSFE"]->id;
}
if (isset($GLOBALS["TSFE"]->type))
$arr[TYPO3_PAGE_TYPE] = $GLOBALS["TSFE"]->type;
if (isset($GLOBALS["TSFE"]->type)) {
$arr[TYPO3_PAGE_TYPE] = $GLOBALS["TSFE"]->type;
}
if (isset($GLOBALS["TSFE"]->sys_language_uid))
$arr[TYPO3_PAGE_LANGUAGE] = $GLOBALS["TSFE"]->sys_language_uid;
if (isset($GLOBALS["TSFE"]->sys_language_uid)) {
$arr[TYPO3_PAGE_LANGUAGE] = $GLOBALS["TSFE"]->sys_language_uid;
}
} else {
// NO T3 environment (called by API): restore from SESSION
if (false !== ($feUser = self::$session->get(SESSION_FE_USER))) {
$arr[TYPO3_FE_USER] = $feUser;
}
if (false !== ($feUserUid = self::$session->get(SESSION_FE_USER_UID))) {
$arr[TYPO3_FE_USER_UID] = $feUserUid;
}
}
self::setVarArray($arr, STORE_TYPO3, true);
}
......
Supports Markdown
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