Completed
Push — master ( 53601d...990ac1 )
by
unknown
07:37 queued 28s
created

RegistrationController::registrationPdfAction()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 15
rs 9.4285
cc 1
eloc 9
nc 1
nop 1
1
<?php
2
3
/**
4
 * Copyright 2014 SURFnet bv
5
 *
6
 * Licensed under the Apache License, Version 2.0 (the "License");
7
 * you may not use this file except in compliance with the License.
8
 * You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
19
namespace Surfnet\StepupSelfService\SelfServiceBundle\Controller;
20
21
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
22
use Surfnet\StepupSelfService\SamlStepupProviderBundle\Provider\ViewConfig;
23
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService;
24
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;
25
use Symfony\Component\HttpFoundation\Request;
26
use Symfony\Component\HttpFoundation\Response;
27
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
28
29
class RegistrationController extends Controller
30
{
31
    /**
32
     * @Template
33
     * @return array
34
     */
35
    public function displaySecondFactorTypesAction()
36
    {
37
        $institutionConfigurationOptions = $this->get('self_service.service.institution_configuration_options')
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $institutionConfigurationOptions exceeds the maximum configured length of 30.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
38
            ->getInstitutionConfigurationOptionsFor($this->getIdentity()->institution);
39
40
        $availableSecondFactors = $this->getParameter('ss.enabled_second_factors');
41
        if (!empty($institutionConfigurationOptions->allowedSecondFactors)) {
42
            $availableSecondFactors = array_intersect(
43
                $availableSecondFactors,
44
                $institutionConfigurationOptions->allowedSecondFactors
45
            );
46
        }
47
        $availableSecondFactors = array_combine($availableSecondFactors, $availableSecondFactors);
48
        $availableGsspSecondFactors = [];
49
50
        foreach ($availableSecondFactors as $index => $secondFactor) {
51
            try {
52
                /** @var ViewConfig $secondFactorConfig */
53
                $secondFactorConfig = $this->get("gssp.view_config.{$secondFactor}");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $secondFactor instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
54
                $availableGsspSecondFactors[$index] = $secondFactorConfig;
55
                // Remove the gssp second factors from the regular second factors.
56
                unset($availableSecondFactors[$index]);
57
            } catch (ServiceNotFoundException $e) {
58
                continue;
59
            }
60
        }
61
62
        return [
63
            'commonName' => $this->getIdentity()->commonName,
64
            'availableSecondFactors' => $availableSecondFactors,
65
            'availableGsspSecondFactors' => $availableGsspSecondFactors,
66
            'tiqrAppAndroidUrl' => $this->getParameter('tiqr_app_android_url'),
67
            'tiqrAppIosUrl'     => $this->getParameter('tiqr_app_ios_url'),
68
        ];
69
    }
70
71
    /**
72
     * @Template
73
     */
74
    public function emailVerificationEmailSentAction()
75
    {
76
        return ['email' => $this->getIdentity()->email];
77
    }
78
79
    /**
80
     * @Template
81
     *
82
     * @param Request $request
83
     * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
84
     */
85
    public function verifyEmailAction(Request $request)
86
    {
87
        $nonce = $request->query->get('n', '');
88
        $identityId = $this->getIdentity()->id;
89
90
        /** @var SecondFactorService $service */
91
        $service = $this->get('surfnet_stepup_self_service_self_service.service.second_factor');
92
93
        $secondFactor = $service->findUnverifiedByVerificationNonce($identityId, $nonce);
94
95
        if ($secondFactor === null) {
96
            throw new NotFoundHttpException('No second factor can be verified using this URL.');
97
        }
98
99
        if ($service->verifyEmail($identityId, $nonce)) {
100
            return $this->redirectToRoute(
101
                'ss_registration_registration_email_sent',
102
                ['secondFactorId' => $secondFactor->id]
103
            );
104
        }
105
106
        return [];
107
    }
108
109
    /**
110
     * @param $secondFactorId
111
     * @return Response
112
     */
113
    public function registrationEmailSentAction($secondFactorId)
114
    {
115
        $identity = $this->getIdentity();
116
117
        $parameters = [
118
            'email'            => $identity->email,
119
            'registrationCode' => $this->get('surfnet_stepup_self_service_self_service.service.second_factor')
120
                ->getRegistrationCode($secondFactorId, $identity->id),
121
        ];
122
123
        $raService         = $this->get('self_service.service.ra');
124
        $raLocationService = $this->get('self_service.service.ra_location');
125
126
        $institutionConfigurationOptions = $this->get('self_service.service.institution_configuration_options')
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $institutionConfigurationOptions exceeds the maximum configured length of 30.

Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.

Loading history...
127
            ->getInstitutionConfigurationOptionsFor($identity->institution);
128
129
        if ($institutionConfigurationOptions->useRaLocations) {
130
            $parameters['raLocations'] = $raLocationService->listRaLocationsFor($identity->institution);
131
        } elseif (!$institutionConfigurationOptions->showRaaContactInformation) {
132
            $parameters['ras'] = $raService->listRasWithoutRaas($identity->institution);
133
        } else {
134
            $parameters['ras'] = $raService->listRas($identity->institution);
135
        }
136
137
        return $this->render(
138
            'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSent.html.twig',
139
            $parameters
140
        );
141
    }
142
}
143