‪TYPO3CMS  11.5
LogoutController.php
Go to the documentation of this file.
1 <?php
2 
3 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 
19 
20 use Psr\Http\Message\ResponseInterface;
21 use Psr\Http\Message\ServerRequestInterface;
26 use ‪TYPO3\CMS\Core\SysLog\Action\Login as SystemLogLoginAction;
27 use ‪TYPO3\CMS\Core\SysLog\Error as SystemLogErrorClassification;
28 use ‪TYPO3\CMS\Core\SysLog\Type as SystemLogType;
30 
37 {
46  public function ‪logoutAction(ServerRequestInterface $request): ResponseInterface
47  {
48  $this->‪processLogout();
49 
50  $redirectUrl = $request->getParsedBody()['redirect'] ?? $request->getQueryParams()['redirect'] ?? '';
51  $redirectUrl = GeneralUtility::sanitizeLocalUrl($redirectUrl);
52  if (empty($redirectUrl)) {
53  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
54  $redirectUrl = (string)$uriBuilder->buildUriFromRoute('login', [], $uriBuilder::ABSOLUTE_URL);
55  }
56  return new ‪RedirectResponse(GeneralUtility::locationHeaderUrl($redirectUrl), 303);
57  }
58 
62  protected function ‪processLogout(): void
63  {
64  if (empty($this->‪getBackendUser()->user['username'])) {
65  return;
66  }
67  // Logout written to log
68  $this->‪getBackendUser()->‪writelog(SystemLogType::LOGIN, SystemLogLoginAction::LOGOUT, SystemLogErrorClassification::MESSAGE, 1, 'User %s logged out from TYPO3 Backend', [$this->‪getBackendUser()->user['username']]);
70  $backendFormProtection = ‪FormProtectionFactory::get();
71  $backendFormProtection->removeSessionTokenFromRegistry();
72  $this->‪getBackendUser()->‪logoff();
73  }
74 
80  protected function ‪getBackendUser()
81  {
82  return ‪$GLOBALS['BE_USER'];
83  }
84 }
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\get
‪static TYPO3 CMS Core FormProtection AbstractFormProtection get($classNameOrType='default',... $constructorArguments)
Definition: FormProtectionFactory.php:73
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection
Definition: BackendFormProtection.php:75
‪TYPO3\CMS\Backend\Controller\LogoutController\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: LogoutController.php:80
‪TYPO3\CMS\Core\SysLog\Action\Login
Definition: Login.php:24
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:40
‪TYPO3\CMS\Backend\Controller\LogoutController
Definition: LogoutController.php:37
‪TYPO3\CMS\Core\SysLog\Error
Definition: Error.php:24
‪TYPO3\CMS\Backend\Controller\LogoutController\logoutAction
‪ResponseInterface logoutAction(ServerRequestInterface $request)
Definition: LogoutController.php:46
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\logoff
‪logoff()
Definition: BackendUserAuthentication.php:2262
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Backend\Controller\LogoutController\processLogout
‪processLogout()
Definition: LogoutController.php:62
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:48
‪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:2020
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:50
‪TYPO3\CMS\Backend\Controller
Definition: AboutController.php:16
‪TYPO3\CMS\Core\SysLog\Type
Definition: Type.php:28