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\SamlStepupProviderBundle\Provider\ViewConfig; |
23
|
|
|
use Surfnet\StepupSelfService\SelfServiceBundle\Service\SecondFactorService; |
24
|
|
|
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException; |
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
|
|
|
* @return array |
34
|
|
|
*/ |
35
|
|
|
public function displaySecondFactorTypesAction() |
36
|
|
|
{ |
37
|
|
|
$institutionConfigurationOptions = $this->get('self_service.service.institution_configuration_options') |
|
|
|
|
38
|
|
|
->getInstitutionConfigurationOptionsFor($this->getIdentity()->institution); |
39
|
|
|
|
40
|
|
|
$availableSecondFactors = $this->getParameter('ss.enabled_second_factors'); |
41
|
|
|
if (!empty($institutionConfigurationOptions->allowedSecondFactors)) { |
42
|
|
|
$availableSecondFactors = array_intersect( |
43
|
|
|
$availableSecondFactors, |
44
|
|
|
$institutionConfigurationOptions->allowedSecondFactors |
45
|
|
|
); |
46
|
|
|
} |
47
|
|
|
$availableSecondFactors = array_combine($availableSecondFactors, $availableSecondFactors); |
48
|
|
|
$availableGsspSecondFactors = []; |
49
|
|
|
|
50
|
|
|
foreach ($availableSecondFactors as $index => $secondFactor) { |
51
|
|
|
try { |
52
|
|
|
/** @var ViewConfig $secondFactorConfig */ |
53
|
|
|
$secondFactorConfig = $this->get("gssp.view_config.{$secondFactor}"); |
|
|
|
|
54
|
|
|
$availableGsspSecondFactors[$index] = $secondFactorConfig; |
55
|
|
|
// Remove the gssp second factors from the regular second factors. |
56
|
|
|
unset($availableSecondFactors[$index]); |
57
|
|
|
} catch (ServiceNotFoundException $e) { |
58
|
|
|
continue; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
return [ |
63
|
|
|
'commonName' => $this->getIdentity()->commonName, |
64
|
|
|
'availableSecondFactors' => $availableSecondFactors, |
65
|
|
|
'availableGsspSecondFactors' => $availableGsspSecondFactors, |
66
|
|
|
'tiqrAppAndroidUrl' => $this->getParameter('tiqr_app_android_url'), |
67
|
|
|
'tiqrAppIosUrl' => $this->getParameter('tiqr_app_ios_url'), |
68
|
|
|
]; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* @Template |
73
|
|
|
*/ |
74
|
|
|
public function emailVerificationEmailSentAction() |
75
|
|
|
{ |
76
|
|
|
return ['email' => $this->getIdentity()->email]; |
77
|
|
|
} |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @Template |
81
|
|
|
* |
82
|
|
|
* @param Request $request |
83
|
|
|
* @return array|\Symfony\Component\HttpFoundation\RedirectResponse |
84
|
|
|
*/ |
85
|
|
|
public function verifyEmailAction(Request $request) |
86
|
|
|
{ |
87
|
|
|
$nonce = $request->query->get('n', ''); |
88
|
|
|
$identityId = $this->getIdentity()->id; |
89
|
|
|
|
90
|
|
|
/** @var SecondFactorService $service */ |
91
|
|
|
$service = $this->get('surfnet_stepup_self_service_self_service.service.second_factor'); |
92
|
|
|
|
93
|
|
|
$secondFactor = $service->findUnverifiedByVerificationNonce($identityId, $nonce); |
94
|
|
|
|
95
|
|
|
if ($secondFactor === null) { |
96
|
|
|
throw new NotFoundHttpException('No second factor can be verified using this URL.'); |
97
|
|
|
} |
98
|
|
|
|
99
|
|
|
if ($service->verifyEmail($identityId, $nonce)) { |
100
|
|
|
return $this->redirectToRoute( |
101
|
|
|
'ss_registration_registration_email_sent', |
102
|
|
|
['secondFactorId' => $secondFactor->id] |
103
|
|
|
); |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
return []; |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param $secondFactorId |
111
|
|
|
* @return Response |
112
|
|
|
*/ |
113
|
|
|
public function registrationEmailSentAction($secondFactorId) |
114
|
|
|
{ |
115
|
|
|
$identity = $this->getIdentity(); |
116
|
|
|
|
117
|
|
|
$parameters = [ |
118
|
|
|
'email' => $identity->email, |
119
|
|
|
'registrationCode' => $this->get('surfnet_stepup_self_service_self_service.service.second_factor') |
120
|
|
|
->getRegistrationCode($secondFactorId, $identity->id), |
121
|
|
|
]; |
122
|
|
|
|
123
|
|
|
$raService = $this->get('self_service.service.ra'); |
124
|
|
|
$raLocationService = $this->get('self_service.service.ra_location'); |
125
|
|
|
|
126
|
|
|
$institutionConfigurationOptions = $this->get('self_service.service.institution_configuration_options') |
|
|
|
|
127
|
|
|
->getInstitutionConfigurationOptionsFor($identity->institution); |
128
|
|
|
|
129
|
|
|
if ($institutionConfigurationOptions->useRaLocations) { |
130
|
|
|
$parameters['raLocations'] = $raLocationService->listRaLocationsFor($identity->institution); |
131
|
|
|
} elseif (!$institutionConfigurationOptions->showRaaContactInformation) { |
132
|
|
|
$parameters['ras'] = $raService->listRasWithoutRaas($identity->institution); |
133
|
|
|
} else { |
134
|
|
|
$parameters['ras'] = $raService->listRas($identity->institution); |
135
|
|
|
} |
136
|
|
|
|
137
|
|
|
return $this->render( |
138
|
|
|
'SurfnetStepupSelfServiceSelfServiceBundle:Registration:registrationEmailSent.html.twig', |
139
|
|
|
$parameters |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
} |
143
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.