Completed
Push — master ( bf4bb9...fe5c1f )
by A.
03:06
created

registrationEmailSentAction()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 29
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 29
rs 8.8571
cc 3
eloc 19
nc 3
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\SecondFactorService;
23
use Symfony\Component\HttpFoundation\Request;
24
use Symfony\Component\HttpFoundation\Response;
25
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
26
27
class RegistrationController extends Controller
28
{
29
    /**
30
     * @Template
31
     */
32
    public function displaySecondFactorTypesAction()
33
    {
34
        $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...
35
            ->getInstitutionConfigurationOptionsFor($this->getIdentity()->institution);
36
37
        $availableSecondFactors = $this->getParameter('ss.enabled_second_factors');
38
        if (!empty($institutionConfigurationOptions->allowedSecondFactors)) {
39
            $availableSecondFactors = array_intersect(
40
                $availableSecondFactors,
41
                $institutionConfigurationOptions->allowedSecondFactors
42
            );
43
        }
44
45
        return [
46
            'commonName' => $this->getIdentity()->commonName,
47
            'availableSecondFactors' => array_combine($availableSecondFactors, $availableSecondFactors),
48
            'tiqrAppAndroidUrl' => $this->getParameter('tiqr_app_android_url'),
49
            'tiqrAppIosUrl'     => $this->getParameter('tiqr_app_ios_url'),
50
        ];
51
    }
52
53
    /**
54
     * @Template
55
     */
56
    public function emailVerificationEmailSentAction()
57
    {
58
        return ['email' => $this->getIdentity()->email];
59
    }
60
61
    /**
62
     * @Template
63
     *
64
     * @param Request $request
65
     * @return array|\Symfony\Component\HttpFoundation\RedirectResponse
66
     */
67
    public function verifyEmailAction(Request $request)
68
    {
69
        $nonce = $request->query->get('n', '');
70
        $identityId = $this->getIdentity()->id;
71
72
        /** @var SecondFactorService $service */
73
        $service = $this->get('surfnet_stepup_self_service_self_service.service.second_factor');
74
75
        $secondFactor = $service->findUnverifiedByVerificationNonce($identityId, $nonce);
76
77
        if ($secondFactor === null) {
78
            throw new NotFoundHttpException('No second factor can be verified using this URL.');
79
        }
80
81
        if ($service->verifyEmail($identityId, $nonce)) {
82
            return $this->redirectToRoute(
83
                'ss_registration_registration_email_sent',
84
                ['secondFactorId' => $secondFactor->id]
85
            );
86
        }
87
88
        return [];
89
    }
90
91
    /**
92
     * @param $secondFactorId
93
     * @return Response
94
     */
95
    public function registrationEmailSentAction($secondFactorId)
96
    {
97
        $identity = $this->getIdentity();
98
99
        $parameters = [
100
            'email'            => $identity->email,
101
            'registrationCode' => $this->get('surfnet_stepup_self_service_self_service.service.second_factor')
102
                ->getRegistrationCode($secondFactorId, $identity->id),
103
        ];
104
105
        $raService         = $this->get('self_service.service.ra');
106
        $raLocationService = $this->get('self_service.service.ra_location');
107
108
        $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...
109
            ->getInstitutionConfigurationOptionsFor($identity->institution);
110
111
        if ($institutionConfigurationOptions->useRaLocations) {
112
            $parameters['raLocations'] = $raLocationService->listRaLocationsFor($identity->institution);
113
        } elseif (!$institutionConfigurationOptions->showRaaContactInformation) {
114
            $parameters['ras'] = $raService->listRasWithoutRaas($identity->institution);
115
        } else {
116
            $parameters['ras'] = $raService->listRas($identity->institution);
117
        }
118
119
        return $this->render(
120
            'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSent.html.twig',
121
            $parameters
122
        );
123
    }
124
}
125