@@ 325-372 (lines=48) @@ | ||
322 | * @param SecondFactorIdentifier $secondFactorIdentifier |
|
323 | * @throws \Exception |
|
324 | */ |
|
325 | public function sendVettedSecondFactorRevokedByRaEmail( |
|
326 | Locale $locale, |
|
327 | CommonName $commonName, |
|
328 | Email $email, |
|
329 | SecondFactorType $secondFactorType, |
|
330 | SecondFactorIdentifier $secondFactorIdentifier |
|
331 | ) { |
|
332 | $subject = $this->translator->trans( |
|
333 | 'mw.mail.second_factor_revoked.subject', |
|
334 | [ |
|
335 | '%tokenType%' => $secondFactorType |
|
336 | ], |
|
337 | 'messages', |
|
338 | $locale->getLocale() |
|
339 | ); |
|
340 | ||
341 | $emailTemplate = $this->emailTemplateService->findByName( |
|
342 | 'second_factor_revoked', |
|
343 | $locale->getLocale(), |
|
344 | $this->fallbackLocale |
|
345 | ); |
|
346 | $parameters = [ |
|
347 | 'isRevokedByRa' => true, |
|
348 | 'templateString' => $emailTemplate->htmlContent, |
|
349 | 'commonName' => $commonName->getCommonName(), |
|
350 | 'tokenType' => $secondFactorType->getSecondFactorType(), |
|
351 | 'tokenIdentifier' => $secondFactorIdentifier->getValue(), |
|
352 | 'selfServiceUrl' => $this->selfServiceUrl, |
|
353 | 'locale' => $locale->getLocale(), |
|
354 | ]; |
|
355 | ||
356 | // Rendering file template instead of string |
|
357 | // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248) |
|
358 | $body = $this->templateEngine->render( |
|
359 | 'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig', |
|
360 | $parameters |
|
361 | ); |
|
362 | ||
363 | /** @var Message $message */ |
|
364 | $message = $this->mailer->createMessage(); |
|
365 | $message |
|
366 | ->setFrom($this->sender->getEmail(), $this->sender->getName()) |
|
367 | ->addTo($email->getEmail(), $commonName->getCommonName()) |
|
368 | ->setSubject($subject) |
|
369 | ->setBody($body, 'text/html', 'utf-8'); |
|
370 | ||
371 | $this->mailer->send($message); |
|
372 | } |
|
373 | ||
374 | /** |
|
375 | * @param Locale $locale |
|
@@ 381-428 (lines=48) @@ | ||
378 | * @param SecondFactorType $secondFactorType |
|
379 | * @param SecondFactorIdentifier $secondFactorIdentifier |
|
380 | */ |
|
381 | public function sendVettedSecondFactorRevokedBySelfEmail( |
|
382 | Locale $locale, |
|
383 | CommonName $commonName, |
|
384 | Email $email, |
|
385 | SecondFactorType $secondFactorType, |
|
386 | SecondFactorIdentifier $secondFactorIdentifier |
|
387 | ) { |
|
388 | $subject = $this->translator->trans( |
|
389 | 'mw.mail.second_factor_revoked.subject', |
|
390 | [ |
|
391 | '%tokenType%' => $secondFactorType |
|
392 | ], |
|
393 | 'messages', |
|
394 | $locale->getLocale() |
|
395 | ); |
|
396 | ||
397 | $emailTemplate = $this->emailTemplateService->findByName( |
|
398 | 'second_factor_revoked', |
|
399 | $locale->getLocale(), |
|
400 | $this->fallbackLocale |
|
401 | ); |
|
402 | $parameters = [ |
|
403 | 'isRevokedByRa' => false, |
|
404 | 'templateString' => $emailTemplate->htmlContent, |
|
405 | 'commonName' => $commonName->getCommonName(), |
|
406 | 'tokenType' => $secondFactorType->getSecondFactorType(), |
|
407 | 'tokenIdentifier' => $secondFactorIdentifier->getValue(), |
|
408 | 'selfServiceUrl' => $this->selfServiceUrl, |
|
409 | 'locale' => $locale->getLocale(), |
|
410 | ]; |
|
411 | ||
412 | // Rendering file template instead of string |
|
413 | // (https://github.com/symfony/symfony/issues/10865#issuecomment-42438248) |
|
414 | $body = $this->templateEngine->render( |
|
415 | 'SurfnetStepupMiddlewareCommandHandlingBundle:SecondFactorMailService:email.html.twig', |
|
416 | $parameters |
|
417 | ); |
|
418 | ||
419 | /** @var Message $message */ |
|
420 | $message = $this->mailer->createMessage(); |
|
421 | $message |
|
422 | ->setFrom($this->sender->getEmail(), $this->sender->getName()) |
|
423 | ->addTo($email->getEmail(), $commonName->getCommonName()) |
|
424 | ->setSubject($subject) |
|
425 | ->setBody($body, 'text/html', 'utf-8'); |
|
426 | ||
427 | $this->mailer->send($message); |
|
428 | } |
|
429 | } |
|
430 |