Skip to content

Commit

Permalink
fix based on comments #722
Browse files Browse the repository at this point in the history
  • Loading branch information
numew committed Jun 6, 2024
1 parent 17a1b50 commit c71a9d3
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/Entity/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 11 additions & 5 deletions src/Service/Mailer/AuthCodeMailer.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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))
);
}
}

0 comments on commit c71a9d3

Please sign in to comment.