‪TYPO3CMS  9.5
LogoutController.php
Go to the documentation of this file.
1 <?php
2 declare(strict_types = 1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
18 use Psr\Http\Message\ResponseInterface;
19 use Psr\Http\Message\ServerRequestInterface;
24 
31 {
40  public function ‪logoutAction(ServerRequestInterface $request): ResponseInterface
41  {
42  $this->‪processLogout();
43 
44  $redirectUrl = $request->getParsedBody()['redirect'] ?? $request->getQueryParams()['redirect'];
45  $redirectUrl = GeneralUtility::sanitizeLocalUrl($redirectUrl);
46  if (empty($redirectUrl)) {
47  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
48  $redirectUrl = (string)$uriBuilder->buildUriFromRoute('login', [], $uriBuilder::ABSOLUTE_URL);
49  }
50  return new ‪RedirectResponse(GeneralUtility::locationHeaderUrl($redirectUrl), 303);
51  }
52 
58  public function ‪logout()
59  {
60  trigger_error('LogoutController->logout() will be replaced by protected method processLogout() in TYPO3 v10.0. Do not call from other extension.', E_USER_DEPRECATED);
61  $this->‪processLogout();
62  }
63 
67  protected function ‪processLogout(): void
68  {
69  if (empty($this->‪getBackendUser()->user['username'])) {
70  return;
71  }
72  // Logout written to log
73  $this->‪getBackendUser()->‪writelog(255, 2, 0, 1, 'User %s logged out from TYPO3 Backend', [$this->‪getBackendUser()->user['username']]);
75  $backendFormProtection = ‪FormProtectionFactory::get();
76  $backendFormProtection->removeSessionTokenFromRegistry();
77  $this->‪getBackendUser()->‪logoff();
78  }
79 
85  protected function ‪getBackendUser()
86  {
87  return ‪$GLOBALS['BE_USER'];
88  }
89 }
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\get
‪static TYPO3 CMS Core FormProtection AbstractFormProtection get($classNameOrType='default',... $constructorArguments)
Definition: FormProtectionFactory.php:72
‪TYPO3\CMS\Backend\Controller\LogoutController\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: LogoutController.php:85
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:35
‪TYPO3\CMS\Backend\Controller\LogoutController
Definition: LogoutController.php:31
‪TYPO3\CMS\Backend\Controller\LogoutController\logoutAction
‪ResponseInterface logoutAction(ServerRequestInterface $request)
Definition: LogoutController.php:40
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\logoff
‪logoff()
Definition: BackendUserAuthentication.php:2758
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:27
‪TYPO3\CMS\Backend\Controller\LogoutController\logout
‪logout()
Definition: LogoutController.php:58
‪TYPO3\CMS\Backend\Controller\LogoutController\processLogout
‪processLogout()
Definition: LogoutController.php:67
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:45
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\writelog
‪int writelog($type, $action, $error, $details_nr, $details, $data, $tablename='', $recuid='', $recpid='', $event_pid=-1, $NEWid='', $userId=0)
Definition: BackendUserAuthentication.php:2351
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:3