From fa8910badb4ce738ca8b3abfc02ee906bee1437e Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Wed, 29 Mar 2023 16:35:16 +0900 Subject: [PATCH 1/2] =?UTF-8?q?FormType=E3=81=AE=E3=83=90=E3=83=AA?= =?UTF-8?q?=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3=E3=81=A8=E9=87=8D?= =?UTF-8?q?=E8=A4=87=E3=81=99=E3=82=8B=E3=81=9F=E3=82=81=E5=89=8A=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Entity/TwoFactorAuthConfig.php | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Entity/TwoFactorAuthConfig.php b/Entity/TwoFactorAuthConfig.php index b2cabbe..94b9149 100644 --- a/Entity/TwoFactorAuthConfig.php +++ b/Entity/TwoFactorAuthConfig.php @@ -53,10 +53,6 @@ class TwoFactorAuthConfig extends AbstractEntity */ private $api_secret = null; - /** - * @Assert\NotBlank() - * @Assert\Length(max=4096) - */ private $plain_api_secret; /** From 8b04cf762b358d6a122594286d6f1ddad9552f0f Mon Sep 17 00:00:00 2001 From: Chihiro Adachi <8196725+chihiro-adachi@users.noreply.github.com> Date: Wed, 29 Mar 2023 16:36:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E3=83=9E=E3=82=B9=E3=82=AF=E5=80=A4?= =?UTF-8?q?=E3=81=A8=E7=95=B0=E3=81=AA=E3=82=8B=E5=A0=B4=E5=90=88=E3=81=AB?= =?UTF-8?q?=E3=83=90=E3=83=AA=E3=83=87=E3=83=BC=E3=82=B7=E3=83=A7=E3=83=B3?= =?UTF-8?q?=E3=81=99=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Form/Type/TwoFactorAuthConfigType.php | 34 +++++++++++++++++++++------ 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/Form/Type/TwoFactorAuthConfigType.php b/Form/Type/TwoFactorAuthConfigType.php index ae7f255..00cd14f 100644 --- a/Form/Type/TwoFactorAuthConfigType.php +++ b/Form/Type/TwoFactorAuthConfigType.php @@ -19,8 +19,12 @@ use Symfony\Component\Form\Extension\Core\Type\TextareaType; use Symfony\Component\Form\Extension\Core\Type\TextType; use Symfony\Component\Form\FormBuilderInterface; +use Symfony\Component\Form\FormError; +use Symfony\Component\Form\FormEvent; +use Symfony\Component\Form\FormEvents; use Symfony\Component\OptionsResolver\OptionsResolver; use Symfony\Component\Validator\Constraints as Assert; +use Symfony\Component\Validator\Validator\ValidatorInterface; class TwoFactorAuthConfigType extends AbstractType { @@ -29,14 +33,17 @@ class TwoFactorAuthConfigType extends AbstractType */ protected $eccubeConfig; + protected ValidatorInterface $validator; + /** * TwoFactorAuthConfigType constructor. * * @param EccubeConfig $eccubeConfig */ - public function __construct(EccubeConfig $eccubeConfig) + public function __construct(EccubeConfig $eccubeConfig, ValidatorInterface $validator) { $this->eccubeConfig = $eccubeConfig; + $this->validator = $validator; } public function buildForm(FormBuilderInterface $builder, array $options) @@ -60,12 +67,6 @@ public function buildForm(FormBuilderInterface $builder, array $options) 'constraints' => [ new Assert\NotBlank(), new Assert\Length(['max' => $this->eccubeConfig['eccube_stext_len']]), - new Assert\Regex( - [ - 'pattern' => '/^[a-zA-Z0-9]+$/i', - 'message' => 'form_error.graph_only', - ] - ), ], ]) ->add('from_phone_number', TextType::class, [ @@ -89,6 +90,25 @@ public function buildForm(FormBuilderInterface $builder, array $options) ]), ], ]); + + $builder->addEventListener(FormEvents::POST_SUBMIT, function (FormEvent $event) { + $form = $event->getForm(); + $data = $event->getData(); + + if ($data['plain_api_secret'] !== $this->eccubeConfig['eccube_default_password']) { + $errors = $this->validator->validate($data['plain_api_secret'], [ + new Assert\Regex([ + 'pattern' => '/^[a-zA-Z0-9]+$/i', + 'message' => 'form_error.graph_only', + ]), + ]); + if ($errors) { + foreach ($errors as $error) { + $form['plain_api_secret']->addError(new FormError($error->getMessage())); + } + } + } + }); } /**