‪TYPO3CMS  ‪main
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;
28 use ‪TYPO3\CMS\Core\SysLog\Action\Login as SystemLogLoginAction;
29 use ‪TYPO3\CMS\Core\SysLog\Error as SystemLogErrorClassification;
30 use ‪TYPO3\CMS\Core\SysLog\Type as SystemLogType;
32 
38 #[AsController]
40 {
41  public function ‪__construct(
42  protected readonly ‪UriBuilder $uriBuilder,
43  protected readonly ‪FormProtectionFactory $formProtectionFactory
44  ) {}
45 
54  public function ‪logoutAction(ServerRequestInterface $request): ResponseInterface
55  {
56  $this->‪processLogout($request);
57 
58  $redirectUrl = $request->getParsedBody()['redirect'] ?? $request->getQueryParams()['redirect'] ?? '';
59  $redirectUrl = GeneralUtility::sanitizeLocalUrl($redirectUrl);
60  if (empty($redirectUrl)) {
61  $redirectUrl = (string)$this->uriBuilder->buildUriFromRoute('login', [], ‪UriBuilder::ABSOLUTE_URL);
62  }
63  return new ‪RedirectResponse(GeneralUtility::locationHeaderUrl($redirectUrl), 303);
64  }
65 
69  protected function ‪processLogout(ServerRequestInterface $request): void
70  {
71  if (empty($this->‪getBackendUser()->user['username'])) {
72  return;
73  }
74  // Logout written to log
75  $this->‪getBackendUser()->writelog(SystemLogType::LOGIN, ‪SystemLogLoginAction::LOGOUT, SystemLogErrorClassification::MESSAGE, 1, 'User %s logged out from TYPO3 Backend', [$this->‪getBackendUser()->user['username']]);
77  $backendFormProtection = $this->formProtectionFactory->createFromRequest($request);
78  $backendFormProtection->removeSessionTokenFromRegistry();
79  $this->‪getBackendUser()->logoff();
80  }
81 
83  {
84  return ‪$GLOBALS['BE_USER'];
85  }
86 }
‪TYPO3\CMS\Backend\Controller\LogoutController\getBackendUser
‪getBackendUser()
Definition: LogoutController.php:82
‪TYPO3\CMS\Core\FormProtection\BackendFormProtection
Definition: BackendFormProtection.php:75
‪TYPO3\CMS\Core\Authentication\LOGOUT
‪@ LOGOUT
Definition: LoginType.php:26
‪TYPO3\CMS\Core\SysLog\Action\Login
Definition: Login.php:24
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:44
‪TYPO3\CMS\Backend\Controller\LogoutController\processLogout
‪processLogout(ServerRequestInterface $request)
Definition: LogoutController.php:69
‪TYPO3\CMS\Backend\Controller\LogoutController
Definition: LogoutController.php:40
‪TYPO3\CMS\Core\SysLog\Error
Definition: Error.php:24
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:62
‪TYPO3\CMS\Backend\Controller\LogoutController\logoutAction
‪ResponseInterface logoutAction(ServerRequestInterface $request)
Definition: LogoutController.php:54
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:30
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:43
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Backend\Attribute\AsController
Definition: AsController.php:25
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Backend\Routing\UriBuilder\ABSOLUTE_URL
‪const ABSOLUTE_URL
Definition: UriBuilder.php:48
‪TYPO3\CMS\Backend\Controller
Definition: AboutController.php:18
‪TYPO3\CMS\Backend\Controller\LogoutController\__construct
‪__construct(protected readonly UriBuilder $uriBuilder, protected readonly FormProtectionFactory $formProtectionFactory)
Definition: LogoutController.php:41
‪TYPO3\CMS\Core\SysLog\Type
Definition: Type.php:28