aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 09:59:46 +0100
committerJeremy Benoist <jeremy.benoist@gmail.com>2015-12-29 11:17:06 +0100
commit23ff8d36199c0cddb5bae4a5010cb71f861eeef8 (patch)
tree0da3a5941c85f80408e49db63ecd3b3ba5347a40 /src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
parentc997cfcc9c161241a6398b0942a1a869688d807a (diff)
downloadwallabag-23ff8d36199c0cddb5bae4a5010cb71f861eeef8.tar.gz
wallabag-23ff8d36199c0cddb5bae4a5010cb71f861eeef8.tar.zst
wallabag-23ff8d36199c0cddb5bae4a5010cb71f861eeef8.zip
Add custom email for 2FA
Related #1490
Diffstat (limited to 'src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php')
-rw-r--r--src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php93
1 files changed, 93 insertions, 0 deletions
diff --git a/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
new file mode 100644
index 00000000..f1960070
--- /dev/null
+++ b/src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
@@ -0,0 +1,93 @@
1<?php
2
3namespace Wallabag\UserBundle\Mailer;
4
5use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
6use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
7use Symfony\Component\Translation\DataCollectorTranslator;
8
9/**
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.
12 */
13class AuthCodeMailer implements AuthCodeMailerInterface
14{
15 /**
16 * SwiftMailer.
17 *
18 * @var \Swift_Mailer
19 */
20 private $mailer;
21
22 /**
23 * Translator for email content.
24 *
25 * @var DataCollectorTranslator
26 */
27 private $translator;
28
29 /**
30 * Sender email address.
31 *
32 * @var string
33 */
34 private $senderEmail;
35
36 /**
37 * Sender name.
38 *
39 * @var string
40 */
41 private $senderName;
42
43 /**
44 * Support URL to report any bugs.
45 *
46 * @var string
47 */
48 private $supportUrl;
49
50 /**
51 * Initialize the auth code mailer with the SwiftMailer object.
52 *
53 * @param \Swift_Mailer $mailer
54 * @param DataCollectorTranslator $translator
55 * @param string $senderEmail
56 * @param string $senderName
57 * @param string $supportUrl
58 */
59 public function __construct(\Swift_Mailer $mailer, DataCollectorTranslator $translator, $senderEmail, $senderName, $supportUrl)
60 {
61 $this->mailer = $mailer;
62 $this->translator = $translator;
63 $this->senderEmail = $senderEmail;
64 $this->senderName = $senderName;
65 $this->supportUrl = $supportUrl;
66 }
67
68 /**
69 * Send the auth code to the user via email.
70 *
71 * @param TwoFactorInterface $user
72 */
73 public function sendAuthCode(TwoFactorInterface $user)
74 {
75 $message = new \Swift_Message();
76 $message
77 ->setTo($user->getEmail())
78 ->setFrom($this->senderEmail, $this->senderName)
79 ->setSubject($this->translator->trans('auth_code.mailer.subject', array(), 'wallabag_user'))
80 ->setBody($this->translator->trans(
81 'auth_code.mailer.body',
82 [
83 '%user%' => $user->getName(),
84 '%code%' => $user->getEmailAuthCode(),
85 '%support%' => $this->supportUrl,
86 ],
87 'wallabag_user'
88 ))
89 ;
90
91 $this->mailer->send($message);
92 }
93}