Init Gitea
This commit is contained in:
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of EC-CUBE
|
||||
*
|
||||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
|
||||
*
|
||||
* http://www.ec-cube.co.jp/
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Plugin\Passkeys\Form\Type\Extension\Admin;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Eccube\Form\Type\Admin\ShopMasterType;
|
||||
use Eccube\Form\Type\ToggleSwitchType;
|
||||
use Plugin\Passkeys\Entity\PasskeysAuthType;
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
||||
class PasskeysAuthBaseSettingTypeExtension extends AbstractTypeExtension
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected EntityManagerInterface $entityManager;
|
||||
|
||||
/**
|
||||
* CouponDetailType constructor.
|
||||
*
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*/
|
||||
public function __construct(
|
||||
EntityManagerInterface $entityManager
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function getExtendedTypes(): iterable
|
||||
{
|
||||
yield ShopMasterType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* buildForm.
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if (!empty($options['skip_add_form'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
$form->add('passkeys_use', ToggleSwitchType::class, [
|
||||
'required' => false,
|
||||
'mapped' => true,
|
||||
]);
|
||||
|
||||
});
|
||||
}
|
||||
}
|
||||
73
Form/Type/Extension/Admin/PasskeysAuthCustomerTypeExtension.php
Executable file
73
Form/Type/Extension/Admin/PasskeysAuthCustomerTypeExtension.php
Executable file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of EC-CUBE
|
||||
*
|
||||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
|
||||
*
|
||||
* http://www.ec-cube.co.jp/
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Plugin\Passkeys\Form\Type\Extension\Admin;
|
||||
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use Eccube\Form\Type\Admin\CustomerType;
|
||||
use Eccube\Form\Type\PhoneNumberType;
|
||||
use Eccube\Form\Type\ToggleSwitchType;
|
||||
use Plugin\Passkeys\Entity\PasskeysAuthType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractTypeExtension;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
use Symfony\Component\Form\FormEvent;
|
||||
use Symfony\Component\Form\FormEvents;
|
||||
|
||||
class PasskeysAuthCustomerTypeExtension extends AbstractTypeExtension
|
||||
{
|
||||
/**
|
||||
* @var EntityManagerInterface
|
||||
*/
|
||||
protected EntityManagerInterface $entityManager;
|
||||
|
||||
/**
|
||||
* CouponDetailType constructor.
|
||||
*
|
||||
* @param EntityManagerInterface $entityManager
|
||||
*/
|
||||
public function __construct(
|
||||
EntityManagerInterface $entityManager
|
||||
) {
|
||||
$this->entityManager = $entityManager;
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*/
|
||||
public static function getExtendedTypes(): iterable
|
||||
{
|
||||
yield CustomerType::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* buildForm.
|
||||
*
|
||||
* @param FormBuilderInterface $builder
|
||||
* @param array $options
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
if (!empty($options['skip_add_form'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$builder->addEventListener(FormEvents::POST_SET_DATA, function (FormEvent $event) {
|
||||
$form = $event->getForm();
|
||||
$form->add('enable_passkeys', ToggleSwitchType::class, [
|
||||
'required' => false,
|
||||
'mapped' => true,
|
||||
]);
|
||||
});
|
||||
}
|
||||
}
|
||||
125
Form/Type/PasskeysAuthConfigType.php
Normal file
125
Form/Type/PasskeysAuthConfigType.php
Normal file
@@ -0,0 +1,125 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of EC-CUBE
|
||||
*
|
||||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
|
||||
*
|
||||
* http://www.ec-cube.co.jp/
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Plugin\Passkeys\Form\Type;
|
||||
|
||||
use Eccube\Common\EccubeConfig;
|
||||
use Plugin\Passkeys\Entity\PasskeysAuthConfig;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
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 PasskeysAuthConfigType extends AbstractType
|
||||
{
|
||||
/**
|
||||
* @var EccubeConfig
|
||||
*/
|
||||
protected $eccubeConfig;
|
||||
|
||||
protected ValidatorInterface $validator;
|
||||
|
||||
/**
|
||||
* PasskeysAuthConfigType constructor.
|
||||
*
|
||||
* @param EccubeConfig $eccubeConfig
|
||||
*/
|
||||
public function __construct(EccubeConfig $eccubeConfig, ValidatorInterface $validator)
|
||||
{
|
||||
$this->eccubeConfig = $eccubeConfig;
|
||||
$this->validator = $validator;
|
||||
}
|
||||
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('api_key', TextType::class, [
|
||||
'required' => true,
|
||||
'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('plain_api_secret', TextType::class, [
|
||||
'required' => true,
|
||||
'constraints' => [
|
||||
new Assert\NotBlank(),
|
||||
new Assert\Length(['max' => $this->eccubeConfig['eccube_stext_len']]),
|
||||
],
|
||||
])
|
||||
->add('from_phone_number', TextType::class, [
|
||||
'required' => true,
|
||||
'constraints' => [
|
||||
new Assert\NotBlank(),
|
||||
new Assert\Length(['max' => $this->eccubeConfig['eccube_stext_len']]),
|
||||
new Assert\Regex(
|
||||
[
|
||||
'pattern' => '/^[0-9]+$/i',
|
||||
'message' => 'form_error.numeric_only',
|
||||
]
|
||||
),
|
||||
],
|
||||
])
|
||||
->add('include_routes', TextareaType::class, [
|
||||
'required' => false,
|
||||
'constraints' => [
|
||||
new Assert\Length([
|
||||
'max' => $this->eccubeConfig['eccube_ltext_len'],
|
||||
]),
|
||||
],
|
||||
]);
|
||||
|
||||
$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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritDoc}
|
||||
*
|
||||
* @see AbstractType::configureOptions
|
||||
*/
|
||||
public function configureOptions(OptionsResolver $resolver)
|
||||
{
|
||||
$resolver->setDefaults([
|
||||
'data_class' => PasskeysAuthConfig::class,
|
||||
]);
|
||||
}
|
||||
}
|
||||
51
Form/Type/PasskeysAuthTypeCustomer.php
Normal file
51
Form/Type/PasskeysAuthTypeCustomer.php
Normal file
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of EC-CUBE
|
||||
*
|
||||
* Copyright(c) EC-CUBE CO.,LTD. All Rights Reserved.
|
||||
*
|
||||
* http://www.ec-cube.co.jp/
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Plugin\Passkeys\Form\Type;
|
||||
|
||||
use Doctrine\ORM\EntityRepository;
|
||||
use Plugin\Passkeys\Entity\PasskeysAuthType;
|
||||
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
|
||||
use Symfony\Component\Form\AbstractType;
|
||||
use Symfony\Component\Form\FormBuilderInterface;
|
||||
|
||||
class PasskeysAuthTypeCustomer extends AbstractType
|
||||
{
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function buildForm(FormBuilderInterface $builder, array $options)
|
||||
{
|
||||
$builder
|
||||
->add('two_factor_auth_type', EntityType::class, [
|
||||
'label' => 'front.setting.system.two_factor_auth.type',
|
||||
'class' => PasskeysAuthType::class,
|
||||
'required' => true,
|
||||
'query_builder' => function (EntityRepository $er) {
|
||||
return $er->createQueryBuilder('tfat')
|
||||
->where('tfat.isDisabled = :id')
|
||||
->setParameter('id', false);
|
||||
},
|
||||
'choice_label' => 'name',
|
||||
'mapped' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function getBlockPrefix()
|
||||
{
|
||||
return 'plg_customer_2fa';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user