‪TYPO3CMS  10.4
SwitchBackUserHook.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
16 namespace ‪TYPO3\CMS\Beuser\Hook;
17 
25 
32 {
40  public function ‪switchBack($params, ‪AbstractUserAuthentication $authentication)
41  {
42  if ($this->‪isAHandledBackendSession($authentication)) {
43  $objectManager = GeneralUtility::makeInstance(ObjectManager::class);
44  $backendUserSessionRepository = $objectManager->get(BackendUserSessionRepository::class);
45  $backendUserSessionRepository->switchBackToOriginalUser($authentication);
47  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
48  ‪HttpUtility::redirect((string)$uriBuilder->buildUriFromRoute('main'));
49  }
50  }
51 
59  protected function ‪isAHandledBackendSession(‪AbstractUserAuthentication $authentication)
60  {
61  return ($authentication instanceof ‪BackendUserAuthentication)
62  && is_array($authentication->user)
63  && (int)$authentication->user['uid'] > 0
64  && (int)$authentication->user['ses_backuserid'] > 0;
65  }
66 }
‪TYPO3\CMS\Beuser\Hook\SwitchBackUserHook
Definition: SwitchBackUserHook.php:32
‪TYPO3\CMS\Beuser\Domain\Repository\BackendUserSessionRepository
Definition: BackendUserSessionRepository.php:30
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Beuser\Hook
Definition: BackendControllerHook.php:16
‪TYPO3\CMS\Beuser\Hook\SwitchBackUserHook\isAHandledBackendSession
‪bool isAHandledBackendSession(AbstractUserAuthentication $authentication)
Definition: SwitchBackUserHook.php:59
‪TYPO3\CMS\Beuser\Hook\SwitchBackUserHook\switchBack
‪switchBack($params, AbstractUserAuthentication $authentication)
Definition: SwitchBackUserHook.php:40
‪TYPO3\CMS\Core\Utility\HttpUtility
Definition: HttpUtility.php:24
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Core\Utility\HttpUtility\redirect
‪static redirect($url, $httpStatus=self::HTTP_STATUS_303)
Definition: HttpUtility.php:106
‪TYPO3\CMS\Extbase\Object\ObjectManager
Definition: ObjectManager.php:28
‪TYPO3\CMS\Core\Authentication\AbstractUserAuthentication
Definition: AbstractUserAuthentication.php:51