‪TYPO3CMS  9.5
SwitchBackUserHook.php
Go to the documentation of this file.
1 <?php
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 
21 
28 {
36  public function ‪switchBack($params, ‪AbstractUserAuthentication $authentication)
37  {
38  if ($this->‪isAHandledBackendSession($authentication)) {
39  $objectManager = GeneralUtility::makeInstance(\‪TYPO3\CMS\‪Extbase\Object\ObjectManager::class);
40  $backendUserSessionRepository = $objectManager->get(\‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository::class);
41  $backendUserSessionRepository->switchBackToOriginalUser($authentication);
43  $uriBuilder = GeneralUtility::makeInstance(\‪TYPO3\CMS\Backend\Routing\UriBuilder::class);
44  ‪HttpUtility::redirect((string)$uriBuilder->buildUriFromRoute('main'));
45  }
46  }
47 
55  protected function ‪isAHandledBackendSession(‪AbstractUserAuthentication $authentication)
56  {
57  return ($authentication instanceof ‪BackendUserAuthentication)
58  && is_array($authentication->user)
59  && (int)$authentication->user['uid'] > 0
60  && (int)$authentication->user['ses_backuserid'] > 0;
61  }
62 }
‪TYPO3\CMS\Extbase\Annotation
Definition: IgnoreValidation.php:4
‪TYPO3
‪TYPO3\CMS\Beuser\Hook\SwitchBackUserHook
Definition: SwitchBackUserHook.php:28
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:45
‪TYPO3\CMS\Beuser\Hook
Definition: BackendControllerHook.php:2
‪TYPO3\CMS\Beuser\Hook\SwitchBackUserHook\isAHandledBackendSession
‪bool isAHandledBackendSession(AbstractUserAuthentication $authentication)
Definition: SwitchBackUserHook.php:55
‪TYPO3\CMS\Beuser\Hook\SwitchBackUserHook\switchBack
‪switchBack($params, AbstractUserAuthentication $authentication)
Definition: SwitchBackUserHook.php:36
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Core\Utility\HttpUtility\redirect
‪static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:103
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:51