Completed
Pull Request — develop (#108)
by A.
02:47
created

RegistrationController   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 105
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 11

Importance

Changes 4
Bugs 0 Features 1
Metric Value
wmc 7
c 4
b 0
f 1
lcom 1
cbo 11
dl 0
loc 105
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A displaySecondFactorTypesAction() 0 11 1
A emailVerificationEmailSentAction() 0 4 1
A verifyEmailAction() 0 23 3
B registrationEmailSentAction() 0 45 2
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');
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
        $templatingEngine = $this->get('templating');
105
106
        $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...
107
            ->getInstitutionConfigurationOptionsFor($identity->institution);
108
109
        if ($institutionConfigurationOptions->useRaLocations) {
110
            return new Response(
111
                $templatingEngine->render(
112
                    'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSentWithRaLocations.html.twig',
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 124 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
113
                    [
114
                        'email'            => $this->getIdentity()->email,
115
                        'registrationCode' => $secondFactorService->getRegistrationCode($secondFactorId, $identity->id),
116
                        'raLocations'      => $raLocationService->listRaLocationsFor($identity->institution),
117
                    ]
118
                )
119
            );
120
        }
121
122
        return new Response(
123
            $templatingEngine->render(
124
                'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSentWithRas.html.twig',
125
                [
126
                    'email'            => $this->getIdentity()->email,
127
                    'registrationCode' => $secondFactorService->getRegistrationCode($secondFactorId, $identity->id),
128
                    'ras'              => $raService->listRas($identity->institution),
129
                ]
130
            )
131
        );
132
    }
133
}
134