forked from TYPO3-directmail/direct_mail
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathTypoScriptFrontendController.php
More file actions
52 lines (47 loc) · 2.01 KB
/
TypoScriptFrontendController.php
File metadata and controls
52 lines (47 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
namespace DirectMailTeam\DirectMail\Hooks;
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
use DirectMailTeam\DirectMail\Utility\DmRegistryUtility;
use TYPO3\CMS\Core\Context\UserAspect;
use TYPO3\CMS\Core\Utility\GeneralUtility;
/**
* Hooks which is called while FE rendering
*
* Class TypoScriptFrontendController
*/
class TypoScriptFrontendController
{
/**
* If a backend user is logged in and
* a frontend usergroup is specified in the GET parameters, use this
* group to simulate access to an access protected page with content to be sent
*/
public function simulateUsergroup($parameters, \TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController $typoScriptFrontendController): void
{
$directMailFeGroup = (int)($GLOBALS['TYPO3_REQUEST']->getQueryParams()['dmail_fe_group'] ?? null);
$accessToken = (string)($GLOBALS['TYPO3_REQUEST']->getQueryParams()['access_token'] ?? null);
if ($directMailFeGroup > 0 && GeneralUtility::makeInstance(DmRegistryUtility::class)->validateAndRemoveAccessToken($accessToken)) {
/** @var UserAspect $userAspect */
$userAspect = $typoScriptFrontendController->getContext()->getAspect('frontend.user');
// we reset the content if required
if (!in_array($directMailFeGroup, $userAspect->getGroupIds(), true)) {
// code was refactor, using a different hook!
$typoScriptFrontendController->getContext()->setAspect(
'frontend.user',
new UserAspect($typoScriptFrontendController->fe_user, [$directMailFeGroup])
);
}
}
}
}