Passed
Push — develop ( 83c6dd...bb507f )
by Torben
68:36 queued 23:31
created

UserRegistrationController::getTypoScriptFrontendController()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Controller;
13
14
use DERHANSEN\SfEventMgt\Domain\Model\Dto\UserRegistrationDemand;
15
use DERHANSEN\SfEventMgt\Domain\Model\Registration;
16
use Psr\Http\Message\ResponseInterface;
17
use TYPO3\CMS\Core\Http\PropagateResponseException;
18
use TYPO3\CMS\Core\Utility\GeneralUtility;
0 ignored issues
show
Bug introduced by
The type TYPO3\CMS\Core\Utility\GeneralUtility was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
19
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
20
use TYPO3\CMS\Frontend\Controller\ErrorController;
21
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
22
23
class UserRegistrationController extends AbstractController
24
{
25
    /**
26
     * Shows a list of all registration of the current frontend user
27
     */
28
    public function listAction(): ResponseInterface
29
    {
30
        $demand = UserRegistrationDemand::createFromSettings($this->settings);
31
        $demand->setUser($this->registrationService->getCurrentFeUserObject());
32
        $registrations = $this->registrationRepository->findRegistrationsByUserRegistrationDemand($demand);
33
        $this->view->assign('registrations', $registrations);
34
35
        return $this->htmlResponse();
36
    }
37
38
    /**
39
     * Shows a detail page for the given registration
40
     */
41
    public function detailAction(Registration $registration): ResponseInterface
42
    {
43
        $this->checkRegistrationAccess($registration);
44
        $this->view->assign('registration', $registration);
45
46
        return $this->htmlResponse();
47
    }
48
49
    /**
50
     * Checks, if the given registration belongs to the current logged in frontend user. If not, a
51
     * page not found response is thrown.
52
     */
53
    public function checkRegistrationAccess(Registration $registration): void
54
    {
55
        if (!$this->getFrontendUser()->user ||
56
            !$registration->getFeUser() ||
57
            $this->getFrontendUser()->user['uid'] !== (int)$registration->getFeUser()->getUid()) {
58
            $response = GeneralUtility::makeInstance(ErrorController::class)->pageNotFoundAction(
59
                $this->request,
60
                'Registration not found.'
61
            );
62
            throw new PropagateResponseException($response, 1671627320);
63
        }
64
    }
65
66
    protected function getFrontendUser(): FrontendUserAuthentication
67
    {
68
        return $this->getTypoScriptFrontendController()->fe_user;
69
    }
70
}
71