Skip to content

Commit

Permalink
Merge pull request #38 from sai-gillingham/hotfix/hide_2_auth_option_…
Browse files Browse the repository at this point in the history
…on_disabled

2段階認証項目表示の変更
  • Loading branch information
dotani1111 authored Mar 23, 2023
2 parents 7e9dc67 + bb10769 commit fbf287b
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
19 changes: 14 additions & 5 deletions Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,27 @@
namespace Plugin\TwoFactorAuthCustomer42;

use Eccube\Event\TemplateEvent;
use Plugin\TwoFactorAuthCustomer42\Repository\TwoFactorAuthTypeRepository;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;

/**
* Class Event.
*/
class Event implements EventSubscriberInterface
{
/**
* @var bool
*/
private bool $hasActiveAuthType;

/**
* Event constructor.
*
* @throws \Exception
*/
public function __construct()
public function __construct(TwoFactorAuthTypeRepository $twoFactorAuthTypeRepository)
{
$this->hasActiveAuthType = $twoFactorAuthTypeRepository->findOneBy(['isDisabled' => false]) !== null;
}

public static function getSubscribedEvents(): array
Expand All @@ -46,13 +53,15 @@ public static function getSubscribedEvents(): array
*/
public function onRenderAdminShopSettingEdit(TemplateEvent $event)
{
// add twig
// add 本人確認認証 twig
$twig = 'TwoFactorAuthCustomer42/Resource/template/admin/shop_edit_sms.twig';
$event->addSnippet($twig);

// add twig
$twig = 'TwoFactorAuthCustomer42/Resource/template/admin/shop_edit_tfa.twig';
$event->addSnippet($twig);
if ($this->hasActiveAuthType) {
// add 2段階認証設定 twig
$twig = 'TwoFactorAuthCustomer42/Resource/template/admin/shop_edit_tfa.twig';
$event->addSnippet($twig);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Doctrine\ORM\EntityManagerInterface;
use Eccube\Form\Type\Admin\ShopMasterType;
use Eccube\Form\Type\ToggleSwitchType;
use Plugin\TwoFactorAuthCustomer42\Entity\TwoFactorAuthType;
use Symfony\Component\Form\AbstractTypeExtension;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Form\FormEvent;
Expand Down Expand Up @@ -61,11 +62,15 @@ public function buildForm(FormBuilderInterface $builder, array $options)

$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
$form = $event->getForm();
$form->add('two_factor_auth_use', ToggleSwitchType::class, [
'required' => false,
'mapped' => true,
])
->add('option_activate_device', ToggleSwitchType::class, [

if ($this->entityManager->getRepository(TwoFactorAuthType::class)->findOneBy(['isDisabled' => false]) !== null) {
$form->add('two_factor_auth_use', ToggleSwitchType::class, [
'required' => false,
'mapped' => true,
]);
}

$form->add('option_activate_device', ToggleSwitchType::class, [
'required' => false,
'mapped' => true,
]);
Expand Down

0 comments on commit fbf287b

Please sign in to comment.