[BUGFIX] Remove non-existing "pseudo-site" logic
[Packages/TYPO3.CMS.git] / typo3 / sysext / backend / Classes / Controller / LogoutController.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Backend\Controller;
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;
20 use TYPO3\CMS\Backend\Routing\UriBuilder;
21 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
22 use TYPO3\CMS\Core\Http\RedirectResponse;
23 use TYPO3\CMS\Core\Utility\GeneralUtility;
24
25 /**
26 * Script Class for logging a user out.
27 * Does not display any content, just calls the logout-function for the current user and then makes a redirect.
28 * @internal This class is a specific Backend controller implementation and is not considered part of the Public TYPO3 API.
29 */
30 class LogoutController
31 {
32 /**
33 * Injects the request object for the current request or subrequest
34 * As this controller goes only through the main() method, it is rather simple for now
35 * This will be split up in an abstract controller once proper routing/dispatcher is in place.
36 *
37 * @param ServerRequestInterface $request the current request
38 * @return ResponseInterface the response with the content
39 */
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
53 /**
54 * Performs the logout processing
55 */
56 protected function processLogout(): void
57 {
58 if (empty($this->getBackendUser()->user['username'])) {
59 return;
60 }
61 // Logout written to log
62 $this->getBackendUser()->writelog(255, 2, 0, 1, 'User %s logged out from TYPO3 Backend', [$this->getBackendUser()->user['username']]);
63 /** @var \TYPO3\CMS\Core\FormProtection\BackendFormProtection $backendFormProtection */
64 $backendFormProtection = FormProtectionFactory::get();
65 $backendFormProtection->removeSessionTokenFromRegistry();
66 $this->getBackendUser()->logoff();
67 }
68
69 /**
70 * Returns the current BE user.
71 *
72 * @return \TYPO3\CMS\Core\Authentication\BackendUserAuthentication
73 */
74 protected function getBackendUser()
75 {
76 return $GLOBALS['BE_USER'];
77 }
78 }