X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=src%2FWallabag%2FUserBundle%2FMailer%2FAuthCodeMailer.php;h=4eea444f249ed685bbe0cd78ca27dd5e9587315d;hb=48b0163d247554d7e2f1ec63b717c8216ea9ec59;hp=f1960070dd24dc52fd56c11654f7a5731a591679;hpb=dad1c546a521159ca65a5a7649651d37728f0e55;p=github%2Fwallabag%2Fwallabag.git diff --git a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php index f1960070..4eea444f 100644 --- a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php +++ b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php @@ -2,9 +2,9 @@ namespace Wallabag\UserBundle\Mailer; -use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface; -use Symfony\Component\Translation\DataCollectorTranslator; +use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; +use Twig\Environment; /** * Custom mailer for TwoFactorBundle email. @@ -20,11 +20,11 @@ class AuthCodeMailer implements AuthCodeMailerInterface private $mailer; /** - * Translator for email content. + * Twig to render the html's email. * - * @var DataCollectorTranslator + * @var Environment */ - private $translator; + private $twig; /** * Sender email address. @@ -47,45 +47,58 @@ class AuthCodeMailer implements AuthCodeMailerInterface */ private $supportUrl; + /** + * Url for the wallabag instance (only used for image in the HTML email template). + * + * @var string + */ + private $wallabagUrl; + /** * Initialize the auth code mailer with the SwiftMailer object. * - * @param \Swift_Mailer $mailer - * @param DataCollectorTranslator $translator - * @param string $senderEmail - * @param string $senderName - * @param string $supportUrl + * @param string $senderEmail + * @param string $senderName + * @param string $supportUrl wallabag support url + * @param string $wallabagUrl wallabag instance url */ - public function __construct(\Swift_Mailer $mailer, DataCollectorTranslator $translator, $senderEmail, $senderName, $supportUrl) + public function __construct(\Swift_Mailer $mailer, Environment $twig, $senderEmail, $senderName, $supportUrl, $wallabagUrl) { $this->mailer = $mailer; - $this->translator = $translator; + $this->twig = $twig; $this->senderEmail = $senderEmail; $this->senderName = $senderName; $this->supportUrl = $supportUrl; + $this->wallabagUrl = $wallabagUrl; } /** * Send the auth code to the user via email. - * - * @param TwoFactorInterface $user */ - public function sendAuthCode(TwoFactorInterface $user) + public function sendAuthCode(TwoFactorInterface $user): void { + $template = $this->twig->loadTemplate('WallabagUserBundle:TwoFactor:email_auth_code.html.twig'); + + $subject = $template->renderBlock('subject', []); + $bodyHtml = $template->renderBlock('body_html', [ + 'user' => $user->getName(), + 'code' => $user->getEmailAuthCode(), + 'support_url' => $this->supportUrl, + 'wallabag_url' => $this->wallabagUrl, + ]); + $bodyText = $template->renderBlock('body_text', [ + 'user' => $user->getName(), + 'code' => $user->getEmailAuthCode(), + 'support_url' => $this->supportUrl, + ]); + $message = new \Swift_Message(); $message - ->setTo($user->getEmail()) + ->setTo($user->getEmailAuthRecipient()) ->setFrom($this->senderEmail, $this->senderName) - ->setSubject($this->translator->trans('auth_code.mailer.subject', array(), 'wallabag_user')) - ->setBody($this->translator->trans( - 'auth_code.mailer.body', - [ - '%user%' => $user->getName(), - '%code%' => $user->getEmailAuthCode(), - '%support%' => $this->supportUrl, - ], - 'wallabag_user' - )) + ->setSubject($subject) + ->setBody($bodyText, 'text/plain') + ->addPart($bodyHtml, 'text/html') ; $this->mailer->send($message);