[TASK] Replace legend.png with CSS/HTML
[Packages/TYPO3.CMS.git] / typo3 / sysext / beuser / Classes / Hook / SwitchBackUserHook.php
1 <?php
2 namespace TYPO3\CMS\Beuser\Hook;
3
4 /**
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Authentication\AbstractUserAuthentication;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19 use TYPO3\CMS\Core\Utility\HttpUtility;
20
21 /**
22 * Backend user switchback, for logoff_pre_processing hook within
23 * \TYPO3\CMS\Core\Authentication\AbstractUserAuthentication class
24 *
25 * @author Kasper Skårhøj (kasperYYYY@typo3.com)
26 * @author Sebastian Kurfürst <sebastian@garbage-group.de>
27 * @author Felix Kopp <felix-source@phorax.com>
28 * @author Pascal Dürsteler <pascal@notionlab.ch>
29 */
30 class SwitchBackUserHook {
31
32 /**
33 * Switch backend user session.
34 *
35 * @param array $params
36 * @param AbstractUserAuthentication $authentication
37 * @see AbstractUserAuthentication
38 * @return void
39 */
40 public function switchBack($params, AbstractUserAuthentication $authentication) {
41 if ($this->isAHandledBackendSession($authentication)) {
42 $objectManager = GeneralUtility::makeInstance(\TYPO3\CMS\Extbase\Object\ObjectManager::class);
43 $backendUserSessionRepository = $objectManager->get(\TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository::class);
44 $backendUserSessionRepository->switchBackToOriginalUser($authentication);
45 HttpUtility::redirect($GLOBALS['BACK_PATH'] . 'backend.php');
46 }
47 }
48
49 /**
50 * Check if the given authentication object is a backend session and
51 * contains all necessary information to allow switching.
52 *
53 * @param AbstractUserAuthentication $authentication
54 * @return bool
55 */
56 protected function isAHandledBackendSession(AbstractUserAuthentication $authentication) {
57 if (
58 $authentication->session_table !== 'be_sessions'
59 || !is_array($authentication->user)
60 || !$authentication->user['uid']
61 || !$authentication->user['ses_backuserid']
62 ) {
63 return FALSE;
64 } else {
65 return TRUE;
66 }
67 }
68
69 }