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