|
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'); |
|
|
|
|
|
|
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 |
|
|
|
|
|
|
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
|
|
|
|
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.