Completed
Push — develop ( b0b139...6288f9 )
by A.
9s
created

EmailProcessor::sendRegistrationEmailWithRas()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
nc 1
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\StepupMiddleware\CommandHandlingBundle\Processor;
20
21
use Broadway\Processor\Processor;
22
use Surfnet\Stepup\Configuration\Value\Institution;
23
use Surfnet\Stepup\Identity\Event\EmailVerifiedEvent;
24
use Surfnet\Stepup\Identity\Event\GssfPossessionProvenEvent;
25
use Surfnet\Stepup\Identity\Event\PhonePossessionProvenEvent;
26
use Surfnet\Stepup\Identity\Event\SecondFactorVettedEvent;
27
use Surfnet\Stepup\Identity\Event\U2fDevicePossessionProvenEvent;
28
use Surfnet\Stepup\Identity\Event\YubikeyPossessionProvenEvent;
29
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\InstitutionConfigurationOptionsService;
30
use Surfnet\StepupMiddleware\ApiBundle\Configuration\Service\RaLocationService;
31
use Surfnet\StepupMiddleware\ApiBundle\Identity\Service\RaListingService;
32
use Surfnet\StepupMiddleware\CommandHandlingBundle\Identity\Service\SecondFactorMailService;
33
34
class EmailProcessor extends Processor
35
{
36
    /**
37
     * @var SecondFactorMailService
38
     */
39
    private $mailService;
40
41
    /**
42
     * @var RaListingService
43
     */
44
    private $raListingService;
45
46
    /**
47
     * @var InstitutionConfigurationOptionsService
48
     */
49
    private $institutionConfigurationOptionsService;
50
51
    /**
52
     * @var RaLocationService
53
     */
54
    private $raLocationsService;
55
56
    /**
57
     * @param SecondFactorMailService $mailService
58
     * @param RaListingService $raListingService
59
     * @param InstitutionConfigurationOptionsService $institutionConfigurationOptionsService
60
     * @param RaLocationService $raLocationsService
61
     */
62
    public function __construct(
63
        SecondFactorMailService $mailService,
64
        RaListingService $raListingService,
65
        InstitutionConfigurationOptionsService $institutionConfigurationOptionsService,
0 ignored issues
show
Comprehensibility Naming introduced by
The variable name $institutionConfigurationOptionsService 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...
66
        RaLocationService $raLocationsService
67
    ) {
68
        $this->mailService                            = $mailService;
69
        $this->raListingService                       = $raListingService;
70
        $this->institutionConfigurationOptionsService = $institutionConfigurationOptionsService;
71
        $this->raLocationsService                     = $raLocationsService;
72
    }
73
74
    public function handlePhonePossessionProvenEvent(PhonePossessionProvenEvent $event)
75
    {
76
        $this->mailService->sendEmailVerificationEmail(
77
            (string) $event->preferredLocale,
78
            (string) $event->commonName,
79
            (string) $event->email,
80
            $event->emailVerificationNonce
81
        );
82
    }
83
84
    public function handleYubikeyPossessionProvenEvent(YubikeyPossessionProvenEvent $event)
85
    {
86
        $this->mailService->sendEmailVerificationEmail(
87
            (string) $event->preferredLocale,
88
            (string) $event->commonName,
89
            (string) $event->email,
90
            $event->emailVerificationNonce
91
        );
92
    }
93
94
    public function handleGssfPossessionProvenEvent(GssfPossessionProvenEvent $event)
95
    {
96
        $this->mailService->sendEmailVerificationEmail(
97
            (string) $event->preferredLocale,
98
            (string) $event->commonName,
99
            (string) $event->email,
100
            $event->emailVerificationNonce
101
        );
102
    }
103
104
    public function handleU2fDevicePossessionProvenEvent(U2fDevicePossessionProvenEvent $event)
105
    {
106
        $this->mailService->sendEmailVerificationEmail(
107
            (string) $event->preferredLocale,
108
            (string) $event->commonName,
109
            (string) $event->email,
110
            $event->emailVerificationNonce
111
        );
112
    }
113
114
    public function handleEmailVerifiedEvent(EmailVerifiedEvent $event)
115
    {
116
        $institution = new Institution($event->identityInstitution->getInstitution());
117
        $institutionConfigurationOptions = $this->institutionConfigurationOptionsService
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...
118
            ->findInstitutionConfigurationOptionsFor($institution);
119
120
        if ($institutionConfigurationOptions->useRaLocationsOption->isEnabled()) {
121
            $this->sendRegistrationEmailWithRaLocations($event, $institution);
122
123
            return;
124
        }
125
126
        $this->sendRegistrationEmailWithRas($event);
127
    }
128
129
    public function handleSecondFactorVettedEvent(SecondFactorVettedEvent $event)
130
    {
131
        $this->mailService->sendVettedEmail($event->preferredLocale, $event->commonName, $event->email);
132
    }
133
134
    /**
135
     * @param EmailVerifiedEvent $event
136
     * @param $institution
137
     */
138
    private function sendRegistrationEmailWithRaLocations(EmailVerifiedEvent $event, $institution)
139
    {
140
        $this->mailService->sendRegistrationEmailWithRaLocations(
141
            (string)$event->preferredLocale,
142
            (string)$event->commonName,
143
            (string)$event->email,
144
            $event->registrationCode,
145
            $this->raLocationsService->listRaLocationsFor($institution)
146
        );
147
    }
148
149
    /**
150
     * @param EmailVerifiedEvent $event
151
     */
152
    private function sendRegistrationEmailWithRas(EmailVerifiedEvent $event)
153
    {
154
        $this->mailService->sendRegistrationEmailWithRas(
155
            (string)$event->preferredLocale,
156
            (string)$event->commonName,
157
            (string)$event->email,
158
            $event->registrationCode,
159
            $this->raListingService->listRegistrationAuthoritiesFor($event->identityInstitution)
160
        );
161
    }
162
}
163