‪TYPO3CMS  10.4
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;
25 use ‪TYPO3\CMS\Core\SysLog\Action\Login as SystemLogLoginAction;
26 use ‪TYPO3\CMS\Core\SysLog\Error as SystemLogErrorClassification;
27 use ‪TYPO3\CMS\Core\SysLog\Type as SystemLogType;
29 
36 {
45  public function ‪logoutAction(ServerRequestInterface $request): ResponseInterface
46  {
47  $this->‪processLogout();
48 
49  $redirectUrl = $request->getParsedBody()['redirect'] ?? $request->getQueryParams()['redirect'];
50  $redirectUrl = GeneralUtility::sanitizeLocalUrl($redirectUrl);
51  if (empty($redirectUrl)) {
52  $uriBuilder = GeneralUtility::makeInstance(UriBuilder::class);
53  $redirectUrl = (string)$uriBuilder->buildUriFromRoute('login', [], $uriBuilder::ABSOLUTE_URL);
54  }
55  return new ‪RedirectResponse(GeneralUtility::locationHeaderUrl($redirectUrl), 303);
56  }
57 
61  protected function ‪processLogout(): void
62  {
63  if (empty($this->‪getBackendUser()->user['username'])) {
64  return;
65  }
66  // Logout written to log
67  $this->‪getBackendUser()->‪writelog(SystemLogType::LOGIN, SystemLogLoginAction::LOGOUT, SystemLogErrorClassification::MESSAGE, 1, 'User %s logged out from TYPO3 Backend', [$this->‪getBackendUser()->user['username']]);
69  $backendFormProtection = ‪FormProtectionFactory::get();
70  $backendFormProtection->removeSessionTokenFromRegistry();
71  $this->‪getBackendUser()->‪logoff();
72  }
73 
79  protected function ‪getBackendUser()
80  {
81  return ‪$GLOBALS['BE_USER'];
82  }
83 }
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory\get
‪static TYPO3 CMS Core FormProtection AbstractFormProtection get($classNameOrType='default',... $constructorArguments)
Definition: FormProtectionFactory.php:74
‪TYPO3\CMS\Backend\Controller\LogoutController\getBackendUser
‪TYPO3 CMS Core Authentication BackendUserAuthentication getBackendUser()
Definition: LogoutController.php:79
‪TYPO3\CMS\Core\SysLog\Action\Login
Definition: Login.php:24
‪TYPO3\CMS\Backend\Routing\UriBuilder
Definition: UriBuilder.php:38
‪TYPO3\CMS\Backend\Controller\LogoutController
Definition: LogoutController.php:36
‪TYPO3\CMS\Core\SysLog\Error
Definition: Error.php:24
‪TYPO3\CMS\Backend\Controller\LogoutController\logoutAction
‪ResponseInterface logoutAction(ServerRequestInterface $request)
Definition: LogoutController.php:45
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication\logoff
‪logoff()
Definition: BackendUserAuthentication.php:2652
‪TYPO3\CMS\Core\Http\RedirectResponse
Definition: RedirectResponse.php:28
‪TYPO3\CMS\Backend\Controller\LogoutController\processLogout
‪processLogout()
Definition: LogoutController.php:61
‪TYPO3\CMS\Core\FormProtection\FormProtectionFactory
Definition: FormProtectionFactory.php:47
‪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:2290
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:5
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Backend\Controller
Definition: AbstractFormEngineAjaxController.php:18
‪TYPO3\CMS\Core\SysLog\Type
Definition: Type.php:24