diff --git a/src/Entity/User.php b/src/Entity/User.php index 4c6d6102c..845d25899 100644 --- a/src/Entity/User.php +++ b/src/Entity/User.php @@ -577,7 +577,7 @@ public function anonymize(): static public function isEmailAuthEnabled(): bool { - return \in_array('ROLE_ADMIN', $this->getRoles()); + return $this->isSuperAdmin(); } public function getEmailAuthRecipient(): string diff --git a/src/Service/Mailer/AuthCodeMailer.php b/src/Service/Mailer/AuthCodeMailer.php index 3f772714d..39a1ce74f 100644 --- a/src/Service/Mailer/AuthCodeMailer.php +++ b/src/Service/Mailer/AuthCodeMailer.php @@ -4,15 +4,21 @@ use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface; use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface; +use Symfony\Component\DependencyInjection\Attribute\Autowire; use Symfony\Component\Mailer\MailerInterface; use Symfony\Component\Mime\Email; class AuthCodeMailer implements AuthCodeMailerInterface { private $mailer; + protected ?string $subject = 'Code de vérification'; + protected ?string $text = 'Votre code de vérification est : %authCode%'; - public function __construct(MailerInterface $mailer) - { + public function __construct( + MailerInterface $mailer, + #[Autowire(env: 'REPLY_TO_EMAIL')] + private string $fromEmail, + ) { $this->mailer = $mailer; } @@ -21,10 +27,10 @@ public function sendAuthCode(TwoFactorInterface $user): void $authCode = $user->getEmailAuthCode(); $this->mailer->send((new Email()) - ->from('ne-pas-repondre@histologe.beta.gouv.fr') + ->from($this->fromEmail) ->to($user->getEmailAuthRecipient()) - ->subject('Code de vérification') - ->text("Votre code de vérification est : $authCode") + ->subject($this->subject) + ->text(str_replace('%authCode%', $authCode, $this->text)) ); } }