aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Mailer
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2016-01-10 12:49:43 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2016-01-21 11:03:27 +0100
commit7ce895bf5e0531b96b2cf0692b9da3814fb742f8 (patch)
tree0727a190800024fed1b5de08562de8dd815b194b /src/Wallabag/UserBundle/Mailer
parente72a943ad244f8b6349e31eb9a148808045b224b (diff)
downloadwallabag-7ce895bf5e0531b96b2cf0692b9da3814fb742f8.tar.gz
wallabag-7ce895bf5e0531b96b2cf0692b9da3814fb742f8.tar.zst
wallabag-7ce895bf5e0531b96b2cf0692b9da3814fb742f8.zip
Use HTML email for 2FA
Related to #1490
Diffstat (limited to 'src/Wallabag/UserBundle/Mailer')
-rw-r--r--src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php47
1 files changed, 27 insertions, 20 deletions
diff --git a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
index be370e71..c04720ae 100644
--- a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
+++ b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
@@ -20,11 +20,11 @@ class AuthCodeMailer implements AuthCodeMailerInterface
20 private $mailer; 20 private $mailer;
21 21
22 /** 22 /**
23 * Translator for email content. 23 * Twig to render the html's email.
24 * 24 *
25 * @var TranslatorInterface 25 * @var \Twig_Environment
26 */ 26 */
27 private $translator; 27 private $twig;
28 28
29 /** 29 /**
30 * Sender email address. 30 * Sender email address.
@@ -50,16 +50,16 @@ class AuthCodeMailer implements AuthCodeMailerInterface
50 /** 50 /**
51 * Initialize the auth code mailer with the SwiftMailer object. 51 * Initialize the auth code mailer with the SwiftMailer object.
52 * 52 *
53 * @param \Swift_Mailer $mailer 53 * @param \Swift_Mailer $mailer
54 * @param TranslatorInterface $translator 54 * @param \Twig_Environment $twig
55 * @param string $senderEmail 55 * @param string $senderEmail
56 * @param string $senderName 56 * @param string $senderName
57 * @param string $supportUrl 57 * @param string $supportUrl
58 */ 58 */
59 public function __construct(\Swift_Mailer $mailer, TranslatorInterface $translator, $senderEmail, $senderName, $supportUrl) 59 public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig, $senderEmail, $senderName, $supportUrl)
60 { 60 {
61 $this->mailer = $mailer; 61 $this->mailer = $mailer;
62 $this->translator = $translator; 62 $this->twig = $twig;
63 $this->senderEmail = $senderEmail; 63 $this->senderEmail = $senderEmail;
64 $this->senderName = $senderName; 64 $this->senderName = $senderName;
65 $this->supportUrl = $supportUrl; 65 $this->supportUrl = $supportUrl;
@@ -72,20 +72,27 @@ class AuthCodeMailer implements AuthCodeMailerInterface
72 */ 72 */
73 public function sendAuthCode(TwoFactorInterface $user) 73 public function sendAuthCode(TwoFactorInterface $user)
74 { 74 {
75 $template = $this->twig->loadTemplate('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig');
76
77 $subject = $template->renderBlock('subject', array());
78 $bodyHtml = $template->renderBlock('body_html', [
79 'user' => $user->getName(),
80 'code' => $user->getEmailAuthCode(),
81 'support' => $this->supportUrl,
82 ]);
83 $bodyText = $template->renderBlock('body_text', [
84 'user' => $user->getName(),
85 'code' => $user->getEmailAuthCode(),
86 'support' => $this->supportUrl,
87 ]);
88
75 $message = new \Swift_Message(); 89 $message = new \Swift_Message();
76 $message 90 $message
77 ->setTo($user->getEmail()) 91 ->setTo($user->getEmail())
78 ->setFrom($this->senderEmail, $this->senderName) 92 ->setFrom($this->senderEmail, $this->senderName)
79 ->setSubject($this->translator->trans('auth_code.mailer.subject', array(), 'wallabag_user')) 93 ->setSubject($subject)
80 ->setBody($this->translator->trans( 94 ->setBody($bodyText, 'text/plain')
81 'auth_code.mailer.body', 95 ->addPart($bodyHtml, 'text/html')
82 [
83 '%user%' => $user->getName(),
84 '%code%' => $user->getEmailAuthCode(),
85 '%support%' => $this->supportUrl,
86 ],
87 'wallabag_user'
88 ))
89 ; 96 ;
90 97
91 $this->mailer->send($message); 98 $this->mailer->send($message);