1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Copyright 2016 SURFnet B.V. |
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\StepupMiddleware\CommandHandlingBundle\Processor; |
20
|
|
|
|
21
|
|
|
use Broadway\Processor\Processor; |
22
|
|
|
use DateInterval; |
23
|
|
|
use Surfnet\Stepup\Configuration\Value\Institution; |
24
|
|
|
use Surfnet\Stepup\DateTime\DateTime; |
25
|
|
|
use Surfnet\Stepup\Identity\Event\EmailVerifiedEvent; |
26
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\InstitutionConfigurationOptionsService; |
27
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\RaLocationService; |
28
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaListingService; |
29
|
|
|
use Surfnet\StepupMiddleware\ApiBundle\Identity\Value\RegistrationAuthorityCredentials; |
30
|
|
|
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\RegistrationMailService; |
31
|
|
|
|
32
|
|
|
final class RegistrationEmailProcessor extends Processor |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* @var RaLocationService |
36
|
|
|
*/ |
37
|
|
|
private $raLocationsService; |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* @var RegistrationMailService |
41
|
|
|
*/ |
42
|
|
|
private $registrationMailService; |
43
|
|
|
|
44
|
|
|
/** |
45
|
|
|
* @var InstitutionConfigurationOptionsService |
46
|
|
|
*/ |
47
|
|
|
private $institutionConfigurationOptionsService; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* @var RaListingService |
51
|
|
|
*/ |
52
|
|
|
private $raListingService; |
53
|
|
|
|
54
|
|
|
public function __construct( |
55
|
|
|
RegistrationMailService $registrationMailService, |
56
|
|
|
RaListingService $raListingService, |
57
|
|
|
InstitutionConfigurationOptionsService $institutionConfigurationOptionsService, |
|
|
|
|
58
|
|
|
RaLocationService $raLocationsService |
59
|
|
|
) { |
60
|
|
|
$this->registrationMailService = $registrationMailService; |
61
|
|
|
$this->raListingService = $raListingService; |
62
|
|
|
$this->institutionConfigurationOptionsService = $institutionConfigurationOptionsService; |
63
|
|
|
$this->raLocationsService = $raLocationsService; |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function handleEmailVerifiedEvent(EmailVerifiedEvent $event) |
67
|
|
|
{ |
68
|
|
|
$institution = new Institution($event->identityInstitution->getInstitution()); |
69
|
|
|
$institutionConfigurationOptions = $this->institutionConfigurationOptionsService |
|
|
|
|
70
|
|
|
->findInstitutionConfigurationOptionsFor($institution); |
71
|
|
|
|
72
|
|
|
if ($institutionConfigurationOptions->useRaLocationsOption->isEnabled()) { |
73
|
|
|
$this->sendRegistrationEmailWithRaLocations($event, $institution); |
74
|
|
|
|
75
|
|
|
return; |
76
|
|
|
} |
77
|
|
|
|
78
|
|
|
$ras = $this->raListingService->listRegistrationAuthoritiesFor($event->identityInstitution); |
79
|
|
|
|
80
|
|
|
if ($institutionConfigurationOptions->showRaaContactInformationOption->isEnabled()) { |
81
|
|
|
$this->sendRegistrationEmailWithRas($event, $ras); |
82
|
|
|
|
83
|
|
|
return; |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
$rasWithoutRaas = array_filter($ras, function (RegistrationAuthorityCredentials $ra) { |
87
|
|
|
return !$ra->isRaa(); |
88
|
|
|
}); |
89
|
|
|
|
90
|
|
|
$this->sendRegistrationEmailWithRas($event, $rasWithoutRaas); |
91
|
|
|
} |
92
|
|
|
|
93
|
|
|
/** |
94
|
|
|
* @param EmailVerifiedEvent $event |
95
|
|
|
* @param Institution $institution |
96
|
|
|
*/ |
97
|
|
|
private function sendRegistrationEmailWithRaLocations(EmailVerifiedEvent $event, Institution $institution) |
98
|
|
|
{ |
99
|
|
|
$this->registrationMailService->sendRegistrationEmailWithRaLocations( |
100
|
|
|
(string)$event->preferredLocale, |
101
|
|
|
(string)$event->commonName, |
102
|
|
|
(string)$event->email, |
103
|
|
|
$event->registrationCode, |
104
|
|
|
$this->getExpirationDateOfRegistration($event), |
105
|
|
|
$this->raLocationsService->listRaLocationsFor($institution) |
106
|
|
|
); |
107
|
|
|
} |
108
|
|
|
|
109
|
|
|
/** |
110
|
|
|
* @param EmailVerifiedEvent $event |
111
|
|
|
* @param RegistrationAuthorityCredentials[] $ras |
112
|
|
|
*/ |
113
|
|
|
private function sendRegistrationEmailWithRas(EmailVerifiedEvent $event, array $ras) |
114
|
|
|
{ |
115
|
|
|
$this->registrationMailService->sendRegistrationEmailWithRas( |
116
|
|
|
(string)$event->preferredLocale, |
117
|
|
|
(string)$event->commonName, |
118
|
|
|
(string)$event->email, |
119
|
|
|
$event->registrationCode, |
120
|
|
|
$this->getExpirationDateOfRegistration($event), |
121
|
|
|
$ras |
122
|
|
|
); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
/** |
126
|
|
|
* @param EmailVerifiedEvent $event |
127
|
|
|
* @return DateTime |
128
|
|
|
*/ |
129
|
|
|
private function getExpirationDateOfRegistration(EmailVerifiedEvent $event) |
130
|
|
|
{ |
131
|
|
|
return $event->registrationRequestedAt->add( |
132
|
|
|
new DateInterval('P14D') |
133
|
|
|
)->endOfDay(); |
134
|
|
|
} |
135
|
|
|
} |
136
|
|
|
|
Very long variable names usually make code harder to read. It is therefore recommended not to make variable names too verbose.