3 namespace Wallabag\UserBundle\Mailer
;
5 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface
;
6 use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface
;
7 use Craue\ConfigBundle\Util\Config
;
10 * Custom mailer for TwoFactorBundle email.
11 * It adds a custom template to the email so user won't get a lonely authentication code but a complete email.
13 class AuthCodeMailer
implements AuthCodeMailerInterface
23 * Twig to render the html's email.
25 * @var \Twig_Environment
30 * Sender email address.
44 * Support URL to report any bugs.
51 * Url for the wallabag instance (only used for image in the HTML email template).
58 * Initialize the auth code mailer with the SwiftMailer object.
60 * @param \Swift_Mailer $mailer
61 * @param \Twig_Environment $twig
62 * @param string $senderEmail
63 * @param string $senderName
64 * @param Config $craueConfig Craue\Config instance to get wallabag support url from database
66 public function __construct(\Swift_Mailer
$mailer, \Twig_Environment
$twig, $senderEmail, $senderName, Config
$craueConfig)
68 $this->mailer
= $mailer;
70 $this->senderEmail
= $senderEmail;
71 $this->senderName
= $senderName;
72 $this->supportUrl
= $craueConfig->get('wallabag_support_url');
73 $this->wallabagUrl
= $craueConfig->get('wallabag_url');
77 * Send the auth code to the user via email.
79 * @param TwoFactorInterface $user
81 public function sendAuthCode(TwoFactorInterface
$user)
83 $template = $this->twig
->loadTemplate('WallabagUserBundle:TwoFactor:email_auth_code.html.twig');
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
,
92 $bodyText = $template->renderBlock('body_text', [
93 'user' => $user->getName(),
94 'code' => $user->getEmailAuthCode(),
95 'support_url' => $this->supportUrl
,
98 $message = new \
Swift_Message();
100 ->setTo($user->getEmail())
101 ->setFrom($this->senderEmail
, $this->senderName
)
102 ->setSubject($subject)
103 ->setBody($bodyText, 'text/plain')
104 ->addPart($bodyHtml, 'text/html')
107 $this->mailer
->send($message);