Completed
Pull Request — develop (#108)
by A.
03:08
created

RegistrationController::verifyEmailAction()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 23
rs 9.0856
c 0
b 0
f 0
cc 3
eloc 12
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\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
        $parameters = [
93
            'email'            => $identity->email,
94
            'registrationCode' => $this->get('surfnet_stepup_self_service_self_service.service.second_factor')
95
                ->getRegistrationCode($secondFactorId, $identity->id),
96
        ];
97
98
        $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...
99
            ->getInstitutionConfigurationOptionsFor($identity->institution);
100
101
        if ($institutionConfigurationOptions->useRaLocations) {
102
            $parameters['raLocations'] = $this->get('self_service.service.ra_location')
103
                ->listRaLocationsFor($identity->institution);
104
        } else {
105
            $parameters['ras'] = $this->get('self_service.service.ra')->listRas($identity->institution);
106
        }
107
108
        return $this->render(
109
            'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSent.html.twig',
110
            $parameters
111
        );
112
    }
113
}
114