aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Mailer
diff options
context:
space:
mode:
authorNicolas LÅ“uillet <nicolas@loeuillet.org>2016-01-21 12:27:47 +0100
committerNicolas LÅ“uillet <nicolas@loeuillet.org>2016-01-21 12:27:47 +0100
commit9aa66d6244935fe86a5598fbdbe518cf6204af2e (patch)
treea616f79e642b9683b3c7b597ed9c4072c0af5cdf /src/Wallabag/UserBundle/Mailer
parente72a943ad244f8b6349e31eb9a148808045b224b (diff)
parentabd454c45633e335d9d63bcd250e760b968f8138 (diff)
downloadwallabag-9aa66d6244935fe86a5598fbdbe518cf6204af2e.tar.gz
wallabag-9aa66d6244935fe86a5598fbdbe518cf6204af2e.tar.zst
wallabag-9aa66d6244935fe86a5598fbdbe518cf6204af2e.zip
Merge pull request #1565 from wallabag/v2-2fa-html
Use HTML email for 2FA
Diffstat (limited to 'src/Wallabag/UserBundle/Mailer')
-rw-r--r--src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php58
1 files changed, 37 insertions, 21 deletions
diff --git a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
index be370e71..6b108dd3 100644
--- a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
+++ b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
@@ -4,7 +4,6 @@ namespace Wallabag\UserBundle\Mailer;
4 4
5use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; 5use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
6use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface; 6use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
7use Symfony\Component\Translation\TranslatorInterface;
8 7
9/** 8/**
10 * Custom mailer for TwoFactorBundle email. 9 * Custom mailer for TwoFactorBundle email.
@@ -20,11 +19,11 @@ class AuthCodeMailer implements AuthCodeMailerInterface
20 private $mailer; 19 private $mailer;
21 20
22 /** 21 /**
23 * Translator for email content. 22 * Twig to render the html's email.
24 * 23 *
25 * @var TranslatorInterface 24 * @var \Twig_Environment
26 */ 25 */
27 private $translator; 26 private $twig;
28 27
29 /** 28 /**
30 * Sender email address. 29 * Sender email address.
@@ -48,21 +47,30 @@ class AuthCodeMailer implements AuthCodeMailerInterface
48 private $supportUrl; 47 private $supportUrl;
49 48
50 /** 49 /**
50 * Url for the wallabag instance.
51 *
52 * @var string
53 */
54 private $wallabagUrl;
55
56 /**
51 * Initialize the auth code mailer with the SwiftMailer object. 57 * Initialize the auth code mailer with the SwiftMailer object.
52 * 58 *
53 * @param \Swift_Mailer $mailer 59 * @param \Swift_Mailer $mailer
54 * @param TranslatorInterface $translator 60 * @param \Twig_Environment $twig
55 * @param string $senderEmail 61 * @param string $senderEmail
56 * @param string $senderName 62 * @param string $senderName
57 * @param string $supportUrl 63 * @param string $supportUrl
64 * @param string $wallabagUrl
58 */ 65 */
59 public function __construct(\Swift_Mailer $mailer, TranslatorInterface $translator, $senderEmail, $senderName, $supportUrl) 66 public function __construct(\Swift_Mailer $mailer, \Twig_Environment $twig, $senderEmail, $senderName, $supportUrl, $wallabagUrl)
60 { 67 {
61 $this->mailer = $mailer; 68 $this->mailer = $mailer;
62 $this->translator = $translator; 69 $this->twig = $twig;
63 $this->senderEmail = $senderEmail; 70 $this->senderEmail = $senderEmail;
64 $this->senderName = $senderName; 71 $this->senderName = $senderName;
65 $this->supportUrl = $supportUrl; 72 $this->supportUrl = $supportUrl;
73 $this->wallabagUrl = $wallabagUrl;
66 } 74 }
67 75
68 /** 76 /**
@@ -72,20 +80,28 @@ class AuthCodeMailer implements AuthCodeMailerInterface
72 */ 80 */
73 public function sendAuthCode(TwoFactorInterface $user) 81 public function sendAuthCode(TwoFactorInterface $user)
74 { 82 {
83 $template = $this->twig->loadTemplate('@WallabagUserBundle/Resources/views/TwoFactor/email_auth_code.html.twig');
84
85 $subject = $template->renderBlock('subject', array());
86 $bodyHtml = $template->renderBlock('body_html', [
87 'user' => $user->getName(),
88 'code' => $user->getEmailAuthCode(),
89 'support_url' => $this->supportUrl,
90 'wallabag_url' => $this->wallabagUrl,
91 ]);
92 $bodyText = $template->renderBlock('body_text', [
93 'user' => $user->getName(),
94 'code' => $user->getEmailAuthCode(),
95 'support_url' => $this->supportUrl,
96 ]);
97
75 $message = new \Swift_Message(); 98 $message = new \Swift_Message();
76 $message 99 $message
77 ->setTo($user->getEmail()) 100 ->setTo($user->getEmail())
78 ->setFrom($this->senderEmail, $this->senderName) 101 ->setFrom($this->senderEmail, $this->senderName)
79 ->setSubject($this->translator->trans('auth_code.mailer.subject', array(), 'wallabag_user')) 102 ->setSubject($subject)
80 ->setBody($this->translator->trans( 103 ->setBody($bodyText, 'text/plain')
81 'auth_code.mailer.body', 104 ->addPart($bodyHtml, 'text/html')
82 [
83 '%user%' => $user->getName(),
84 '%code%' => $user->getEmailAuthCode(),
85 '%support%' => $this->supportUrl,
86 ],
87 'wallabag_user'
88 ))
89 ; 105 ;
90 106
91 $this->mailer->send($message); 107 $this->mailer->send($message);