1a504391e5e923ec9a7fb9ae0d951e97f9e3ae02
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / Hook / SwitchBackUserHook.php
1 <?php
2 namespace TYPO3\CMS\Beuser\Hook;
3
4 /***************************************************************
5 * Copyright notice
6 *
7 * (c) 2012 Felix Kopp <felix-source@phorax.com>
8 * All rights reserved
9 *
10 * This script is part of the TYPO3 project. The TYPO3 project is
11 * free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * The GNU General Public License can be found at
17 * http://www.gnu.org/copyleft/gpl.html.
18 *
19 * This script is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 *
24 * This copyright notice MUST APPEAR in all copies of the script!
25 ***************************************************************/
26 /**
27 * Backend user switchback, for logoff_pre_processing hook within t3lib_userauth class
28 *
29 * @author Kasper Skårhøj (kasperYYYY@typo3.com)
30 * @author Sebastian Kurfürst <sebastian@garbage-group.de>
31 * @author Felix Kopp <felix-source@phorax.com>
32 */
33 class SwitchBackUserHook {
34
35 /**
36 * Switch backen user session
37 *
38 * @param array $params
39 * @param \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication $that
40 * @see t3lib_userauth::logoff()
41 * @todo Define visibility
42 */
43 public function switchBack($params, $that) {
44 // Is a backend session handled?
45 if ($that->session_table !== 'be_sessions' || !$that->user['uid'] || !$that->user['ses_backuserid']) {
46 return;
47 }
48 // @TODO: Move update functionality to Tx_Beuser_Domain_Repository_BackendUserSessionRepository
49 $updateData = array(
50 'ses_userid' => $that->user['ses_backuserid'],
51 'ses_backuserid' => 0
52 );
53 $GLOBALS['TYPO3_DB']->exec_UPDATEquery('be_sessions', 'ses_id = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr($GLOBALS['BE_USER']->id, 'be_sessions') . ' AND ses_name = ' . $GLOBALS['TYPO3_DB']->fullQuoteStr(\TYPO3\CMS\Core\Authentication\BackendUserAuthentication::getCookieName(), 'be_sessions') . ' AND ses_userid=' . intval($GLOBALS['BE_USER']->user['uid']), $updateData);
54 $redirectUrl = $GLOBALS['BACK_PATH'] . 'index.php' . ($GLOBALS['TYPO3_CONF_VARS']['BE']['interfaces'] ? '' : '?commandLI=1');
55 \TYPO3\CMS\Core\Utility\HttpUtility::redirect($redirectUrl);
56 }
57
58 }
59
60
61 ?>