[!!!][TASK] Extract testing framework for TYPO3
[Packages/TYPO3.CMS.git] / components / testing_framework / core / Functional / Framework / Frontend / Hook / FrontendUserHandler.php
1 <?php
2 namespace TYPO3\CMS\Components\TestingFramework\Core\Functional\Framework\Frontend\Hook;
3
4 /*
5 * This file is part of the TYPO3 CMS project.
6 *
7 * It is free software; you can redistribute it and/or modify it under
8 * the terms of the GNU General Public License, either version 2
9 * of the License, or any later version.
10 *
11 * For the full copyright and license information, please read the
12 * LICENSE.txt file that was distributed with this source code.
13 *
14 * The TYPO3 project - inspiring people to share!
15 */
16
17 use TYPO3\CMS\Core\Database\ConnectionPool;
18 use TYPO3\CMS\Core\Utility\GeneralUtility;
19
20 /**
21 * Handler for frontend user
22 */
23 class FrontendUserHandler implements \TYPO3\CMS\Core\SingletonInterface
24 {
25 /**
26 * Initialize
27 *
28 * @param array $parameters
29 * @param \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $frontendController
30 */
31 public function initialize(array $parameters, \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $frontendController)
32 {
33 $frontendUserId = (int)GeneralUtility::_GP('frontendUserId');
34 $frontendController->fe_user->checkPid = 0;
35
36 $frontendUser = GeneralUtility::makeInstance(ConnectionPool::class)
37 ->getConnectionForTable('fe_users')
38 ->select(['*'], 'fe_users', ['uid' => $frontendUserId])
39 ->fetch();
40 if (is_array($frontendUser)) {
41 $frontendController->loginUser = 1;
42 $frontendController->fe_user->createUserSession($frontendUser);
43 $frontendController->fe_user->user = $GLOBALS['TSFE']->fe_user->fetchUserSession();
44 $frontendController->initUserGroups();
45 }
46 }
47 }