Completed
Pull Request — develop (#108)
by A.
04:17 queued 01:04
created

registrationEmailSentAction()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 46
Code Lines 22

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 46
rs 8.9411
cc 2
eloc 22
nc 2
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\SelfServiceBundle\Service\InstitutionConfigurationOptionsService;
23
use Surfnet\StepupSelfService\SelfServiceBundle\Service\RaLocationService;
24
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService;
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
     */
34
    public function displaySecondFactorTypesAction()
35
    {
36
        $enabledSecondFactors = $this->getParameter('ss.enabled_second_factors');
37
38
        return [
39
            'commonName' => $this->getIdentity()->commonName,
40
            'enabledSecondFactors' => array_combine($enabledSecondFactors, $enabledSecondFactors),
41
            'tiqrAppAndroidUrl' => $this->getParameter('tiqr_app_android_url'),
42
            'tiqrAppIosUrl'     => $this->getParameter('tiqr_app_ios_url'),
43
        ];
44
    }
45
46
    /**
47
     * @Template
48
     */
49
    public function emailVerificationEmailSentAction()
50
    {
51
        return ['email' => $this->getIdentity()->email];
52
    }
53
54
    /**
55
     * @Template
56
     *
57
     * @param Request $request
58
     * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
59
     */
60
    public function verifyEmailAction(Request $request)
61
    {
62
        $nonce = $request->query->get('n', '');
63
        $identityId = $this->getIdentity()->id;
64
65
        /** @var SecondFactorService $service */
66
        $service = $this->get('surfnet_stepup_self_service_self_service.service.second_factor');
67
68
        $secondFactor = $service->findUnverifiedByVerificationNonce($identityId, $nonce);
69
70
        if ($secondFactor === null) {
71
            throw new NotFoundHttpException('No second factor can be verified using this URL.');
72
        }
73
74
        if ($service->verifyEmail($identityId, $nonce)) {
75
            return $this->redirectToRoute(
76
                'ss_registration_registration_email_sent',
77
                ['secondFactorId' => $secondFactor->id]
78
            );
79
        }
80
81
        return [];
82
    }
83
84
    /**
85
     * @param $secondFactorId
86
     * @return array|Response
87
     */
88
    public function registrationEmailSentAction($secondFactorId)
89
    {
90
        $identity = $this->getIdentity();
91
92
        /** @var SecondFactorService $secondFactorService */
93
        $secondFactorService = $this->get('surfnet_stepup_self_service_self_service.service.second_factor');
94
95
        /** @var \Surfnet\StepupSelfService\SelfServiceBundle\Service\RaService $raService */
96
        $raService = $this->get('self_service.service.ra');
0 ignored issues
show
Unused Code introduced by
$raService is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
97
98
        /** @var InstitutionConfigurationOptionsService $institutionConfigurationOptionsService */
99
        $institutionConfigurationOptionsService = $this->get('self_service.service.institution_configuration_options');
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $institutionConfigurationOptionsService 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...
100
101
        /** @var RaLocationService $raLocationService */
102
        $raLocationService = $this->get('self_service.service.ra_location');
103
104
        /** @var  $templatingEngine */
105
        $templatingEngine = $this->get('templating');
106
107
        $institutionConfigurationOptions = $institutionConfigurationOptionsService
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...
108
            ->getInstitutionConfigurationOptionsFor($identity->institution);
109
110
        if ($institutionConfigurationOptions->useRaLocations) {
111
            return new Response(
112
                $templatingEngine->render(
113
                    '@SurfnetStepupSelfServiceSelfService/Registration/registrationEmailSentWithRaLocations.html.twig',
114
                    [
115
                        'email'            => $this->getIdentity()->email,
116
                        'registrationCode' => $secondFactorService->getRegistrationCode($secondFactorId, $identity->id),
117
                        'raLocations'      => $raLocationService->listRaLocationsFor($identity->institution),
118
                    ]
119
                )
120
            );
121
        }
122
123
        return new Response(
124
            $templatingEngine->render(
125
                '@SurfnetStepupSelfServiceSelfService/Registration/registrationEmailSentWithRas.html.twig',
126
                [
127
                    'email'            => $this->getIdentity()->email,
128
                    'registrationCode' => $secondFactorService->getRegistrationCode($secondFactorId, $identity->id),
129
                    'raLocations'      => $raLocationService->listRaLocationsFor($identity->institution),
130
                ]
131
            )
132
        );
133
    }
134
}
135