1 | <?php |
||
32 | class SecondFactorMailService |
||
33 | { |
||
34 | /** |
||
35 | * @var Mailer |
||
36 | */ |
||
37 | private $mailer; |
||
38 | |||
39 | /** |
||
40 | * @var Sender |
||
41 | */ |
||
42 | private $sender; |
||
43 | |||
44 | /** |
||
45 | * @var TranslatorInterface |
||
46 | */ |
||
47 | private $translator; |
||
48 | |||
49 | /** |
||
50 | * @var EngineInterface |
||
51 | */ |
||
52 | private $templateEngine; |
||
53 | |||
54 | /** |
||
55 | * @var string |
||
56 | */ |
||
57 | private $emailVerificationUrlTemplate; |
||
58 | |||
59 | /** |
||
60 | * @var \Surfnet\StepupMiddleware\CommandHandlingBundle\Configuration\Service\EmailTemplateService |
||
61 | */ |
||
62 | private $emailTemplateService; |
||
63 | |||
64 | /** |
||
65 | * @var string |
||
66 | */ |
||
67 | private $fallbackLocale; |
||
68 | |||
69 | /** |
||
70 | * @param Mailer $mailer |
||
71 | * @param Sender $sender |
||
72 | * @param TranslatorInterface $translator |
||
73 | * @param EngineInterface $templateEngine |
||
74 | * @param string $emailVerificationUrlTemplate |
||
75 | * @param EmailTemplateService $emailTemplateService |
||
76 | * @param string $fallbackLocale |
||
77 | */ |
||
78 | public function __construct( |
||
79 | Mailer $mailer, |
||
80 | Sender $sender, |
||
81 | TranslatorInterface $translator, |
||
82 | EngineInterface $templateEngine, |
||
83 | $emailVerificationUrlTemplate, |
||
84 | EmailTemplateService $emailTemplateService, |
||
85 | $fallbackLocale |
||
86 | ) { |
||
87 | $this->mailer = $mailer; |
||
88 | $this->sender = $sender; |
||
89 | $this->translator = $translator; |
||
90 | $this->templateEngine = $templateEngine; |
||
91 | $this->emailVerificationUrlTemplate = $emailVerificationUrlTemplate; |
||
92 | $this->emailTemplateService = $emailTemplateService; |
||
93 | $this->fallbackLocale = $fallbackLocale; |
||
94 | } |
||
95 | |||
96 | /** |
||
97 | * @param string $locale |
||
98 | * @param string $commonName |
||
99 | * @param string $email |
||
100 | * @param string $verificationNonce |
||
101 | */ |
||
102 | public function sendEmailVerificationEmail( |
||
147 | |||
148 | /** |
||
149 | * @param string $locale |
||
150 | * @param string $commonName |
||
151 | * @param string $email |
||
152 | * @param string $registrationCode |
||
153 | * @param RegistrationAuthorityCredentials[] $ras |
||
154 | */ |
||
155 | public function sendRegistrationEmail( |
||
156 | $locale, |
||
157 | $commonName, |
||
158 | $email, |
||
159 | $registrationCode, |
||
160 | array $ras |
||
161 | ) { |
||
162 | $subject = $this->translator->trans( |
||
163 | 'ss.mail.registration_email.subject', |
||
164 | ['%commonName%' => $commonName], |
||
165 | null, |
||
166 | $locale |
||
167 | ); |
||
168 | |||
169 | $emailTemplate = $this->emailTemplateService->findByName( |
||
170 | 'registration_code', |
||
171 | $locale, |
||
172 | $this->fallbackLocale |
||
173 | ); |
||
174 | $parameters = [ |
||
175 | 'templateString' => $emailTemplate->htmlContent, |
||
176 | 'locale' => $locale, |
||
177 | 'commonName' => $commonName, |
||
178 | 'email' => $email, |
||
179 | 'registrationCode' => $registrationCode, |
||
180 | 'ras' => $ras, |
||
181 | ]; |
||
182 | |||
183 | // Rendering file template instead of string |
||
184 | // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248) |
||
185 | $body = $this->templateEngine->render( |
||
186 | 'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig', |
||
187 | $parameters |
||
188 | ); |
||
189 | |||
190 | /** @var Message $message */ |
||
191 | $message = $this->mailer->createMessage(); |
||
192 | $message |
||
193 | ->setFrom($this->sender->getEmail(), $this->sender->getName()) |
||
194 | ->addTo($email, $commonName) |
||
195 | ->setSubject($subject) |
||
196 | ->setBody($body, 'text/html', 'utf-8'); |
||
197 | |||
198 | $this->mailer->send($message); |
||
199 | } |
||
200 | |||
201 | /** |
||
202 | * @param Locale $locale |
||
203 | * @param CommonName $commonName |
||
204 | * @param Email $email |
||
205 | */ |
||
206 | public function sendVettedEmail( |
||
247 | } |
||
248 |