Files
kupshop/bundles/KupShop/TwoFactorBundle/Util/TwoFactorMailer.php
2025-08-02 16:30:27 +02:00

49 lines
1.5 KiB
PHP

<?php
declare(strict_types=1);
namespace KupShop\TwoFactorBundle\Util;
use KupShop\KupShopBundle\Util\Mail\SMSSendingInterface;
use KupShop\TwoFactorBundle\Email\TwoFactorCodeEmail;
use KupShop\TwoFactorBundle\Security\TwoFactorUser;
use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
use Symfony\Contracts\Service\Attribute\Required;
class TwoFactorMailer implements AuthCodeMailerInterface
{
#[Required]
public TwoFactorCodeEmail $email;
protected SMSSendingInterface $SMSHandler;
public function sendAuthCode(TwoFactorInterface $user): void
{
if (!$user instanceof TwoFactorUser) {
return;
}
$authCode = $user->getEmailAuthCode();
// Na review chci poslat mail, telfa tam není aktivní
if ((findModule(\Modules::TELFA) || findModule(\Modules::DAKTELA)) && !isDevelopment()) {
$phone = $user->getKupshopUser()['phone'];
if (empty($text = $this->email->getSMSText(['2FA_KOD' => $authCode]))) {
$text = $authCode;
}
$this->SMSHandler->sendSMS($phone, $text);
} else {
$email = $this->email->getEmail(['2FA_KOD' => $authCode]);
$email['to'] = $user->getEmailAuthRecipient();
$this->email->sendEmail($email);
}
}
#[Required]
public function setSmsHandler(SMSSendingInterface $SMSHandler)
{
$this->SMSHandler = $SMSHandler;
}
}