This commit is contained in:
Xes
2025-08-14 22:41:49 +02:00
parent 2de81ccc46
commit 8ce45119b6
39774 changed files with 4309466 additions and 0 deletions

View File

@@ -0,0 +1,84 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\DataTransformer;
use FOS\UserBundle\Model\UserInterface;
use FOS\UserBundle\Model\UserManagerInterface;
use Symfony\Component\Form\DataTransformerInterface;
use Symfony\Component\Form\Exception\UnexpectedTypeException;
/**
* Transforms between a UserInterface instance and a username string.
*
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
*/
class UserToUsernameTransformer implements DataTransformerInterface
{
/**
* @var UserManagerInterface
*/
protected $userManager;
/**
* UserToUsernameTransformer constructor.
*
* @param UserManagerInterface $userManager
*/
public function __construct(UserManagerInterface $userManager)
{
$this->userManager = $userManager;
}
/**
* Transforms a UserInterface instance into a username string.
*
* @param UserInterface|null $value UserInterface instance
*
* @return string|null Username
*
* @throws UnexpectedTypeException if the given value is not a UserInterface instance
*/
public function transform($value)
{
if (null === $value) {
return;
}
if (!$value instanceof UserInterface) {
throw new UnexpectedTypeException($value, 'FOS\UserBundle\Model\UserInterface');
}
return $value->getUsername();
}
/**
* Transforms a username string into a UserInterface instance.
*
* @param string $value Username
*
* @return UserInterface the corresponding UserInterface instance
*
* @throws UnexpectedTypeException if the given value is not a string
*/
public function reverseTransform($value)
{
if (null === $value || '' === $value) {
return;
}
if (!is_string($value)) {
throw new UnexpectedTypeException($value, 'string');
}
return $this->userManager->findUserByUsername($value);
}
}

View File

@@ -0,0 +1,22 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Factory;
use Symfony\Component\Form\FormInterface;
interface FactoryInterface
{
/**
* @return FormInterface
*/
public function createForm();
}

View File

@@ -0,0 +1,63 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Factory;
use Symfony\Component\Form\FormFactoryInterface;
class FormFactory implements FactoryInterface
{
/**
* @var FormFactoryInterface
*/
private $formFactory;
/**
* @var string
*/
private $name;
/**
* @var string
*/
private $type;
/**
* @var array
*/
private $validationGroups;
/**
* FormFactory constructor.
*
* @param FormFactoryInterface $formFactory
* @param string $name
* @param string $type
* @param array $validationGroups
*/
public function __construct(FormFactoryInterface $formFactory, $name, $type, array $validationGroups = null)
{
$this->formFactory = $formFactory;
$this->name = $name;
$this->type = $type;
$this->validationGroups = $validationGroups;
}
/**
* {@inheritdoc}
*/
public function createForm(array $options = array())
{
$options = array_merge(array('validation_groups' => $this->validationGroups), $options);
return $this->formFactory->createNamed($this->name, $this->type, null, $options);
}
}

View File

@@ -0,0 +1,105 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Constraints\NotBlank;
class ChangePasswordFormType extends AbstractType
{
/**
* @var string
*/
private $class;
/**
* @param string $class The User class name
*/
public function __construct($class)
{
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$constraintsOptions = array(
'message' => 'fos_user.current_password.invalid',
);
if (!empty($options['validation_groups'])) {
$constraintsOptions['groups'] = array(reset($options['validation_groups']));
}
$builder->add('current_password', PasswordType::class, array(
'label' => 'form.current_password',
'translation_domain' => 'FOSUserBundle',
'mapped' => false,
'constraints' => array(
new NotBlank(),
new UserPassword($constraintsOptions),
),
'attr' => array(
'autocomplete' => 'current-password',
),
));
$builder->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'options' => array(
'translation_domain' => 'FOSUserBundle',
'attr' => array(
'autocomplete' => 'new-password',
),
),
'first_options' => array('label' => 'form.new_password'),
'second_options' => array('label' => 'form.new_password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
));
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'csrf_token_id' => 'change_password',
));
}
// BC for SF < 3.0
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'fos_user_change_password';
}
}

View File

@@ -0,0 +1,69 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class GroupFormType extends AbstractType
{
/**
* @var string
*/
private $class;
/**
* @param string $class The Group class name
*/
public function __construct($class)
{
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('name', null, array('label' => 'form.group_name', 'translation_domain' => 'FOSUserBundle'));
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'csrf_token_id' => 'group',
));
}
// BC for SF < 3.0
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'fos_user_group';
}
}

View File

@@ -0,0 +1,108 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Security\Core\Validator\Constraints\UserPassword;
use Symfony\Component\Validator\Constraints\NotBlank;
class ProfileFormType extends AbstractType
{
/**
* @var string
*/
private $class;
/**
* @param string $class The User class name
*/
public function __construct($class)
{
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$this->buildUserForm($builder, $options);
$constraintsOptions = array(
'message' => 'fos_user.current_password.invalid',
);
if (!empty($options['validation_groups'])) {
$constraintsOptions['groups'] = array(reset($options['validation_groups']));
}
$builder->add('current_password', PasswordType::class, array(
'label' => 'form.current_password',
'translation_domain' => 'FOSUserBundle',
'mapped' => false,
'constraints' => array(
new NotBlank(),
new UserPassword($constraintsOptions),
),
'attr' => array(
'autocomplete' => 'current-password',
),
));
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'csrf_token_id' => 'profile',
));
}
// BC for SF < 3.0
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'fos_user_profile';
}
/**
* Builds the embedded form representing the user.
*
* @param FormBuilderInterface $builder
* @param array $options
*/
protected function buildUserForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
->add('email', EmailType::class, array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
;
}
}

View File

@@ -0,0 +1,87 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class RegistrationFormType extends AbstractType
{
/**
* @var string
*/
private $class;
/**
* @param string $class The User class name
*/
public function __construct($class)
{
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class, array('label' => 'form.email', 'translation_domain' => 'FOSUserBundle'))
->add('username', null, array('label' => 'form.username', 'translation_domain' => 'FOSUserBundle'))
->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'options' => array(
'translation_domain' => 'FOSUserBundle',
'attr' => array(
'autocomplete' => 'new-password',
),
),
'first_options' => array('label' => 'form.password'),
'second_options' => array('label' => 'form.password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
))
;
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'csrf_token_id' => 'registration',
));
}
// BC for SF < 3.0
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'fos_user_registration';
}
}

View File

@@ -0,0 +1,82 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Type;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
class ResettingFormType extends AbstractType
{
/**
* @var string
*/
private $class;
/**
* @param string $class The User class name
*/
public function __construct($class)
{
$this->class = $class;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->add('plainPassword', RepeatedType::class, array(
'type' => PasswordType::class,
'options' => array(
'translation_domain' => 'FOSUserBundle',
'attr' => array(
'autocomplete' => 'new-password',
),
),
'first_options' => array('label' => 'form.new_password'),
'second_options' => array('label' => 'form.new_password_confirmation'),
'invalid_message' => 'fos_user.password.mismatch',
));
}
/**
* {@inheritdoc}
*/
public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults(array(
'data_class' => $this->class,
'csrf_token_id' => 'resetting',
));
}
// BC for SF < 3.0
/**
* {@inheritdoc}
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'fos_user_resetting';
}
}

View File

@@ -0,0 +1,74 @@
<?php
/*
* This file is part of the FOSUserBundle package.
*
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace FOS\UserBundle\Form\Type;
use FOS\UserBundle\Form\DataTransformer\UserToUsernameTransformer;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
/**
* Form type for representing a UserInterface instance by its username string.
*
* @author Thibault Duplessis <thibault.duplessis@gmail.com>
*/
class UsernameFormType extends AbstractType
{
/**
* @var UserToUsernameTransformer
*/
protected $usernameTransformer;
/**
* Constructor.
*
* @param UserToUsernameTransformer $usernameTransformer
*/
public function __construct(UserToUsernameTransformer $usernameTransformer)
{
$this->usernameTransformer = $usernameTransformer;
}
/**
* {@inheritdoc}
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder->addModelTransformer($this->usernameTransformer);
}
/**
* {@inheritdoc}
*/
public function getParent()
{
return TextType::class;
}
// BC for SF < 3.0
/**
* @return string
*/
public function getName()
{
return $this->getBlockPrefix();
}
/**
* {@inheritdoc}
*/
public function getBlockPrefix()
{
return 'fos_user_username';
}
}