<?php
namespace App\Form;
use App\Entity\User;
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\Extension\Core\Type\TextType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Validator\Constraints\Email;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;
class RegistrationFormType extends AbstractType
{
public function buildForm(FormBuilderInterface $builder, array $options): void
{
$builder
->add('email', EmailType::class, [
'required' => false,
'invalid_message' => 'Email invalide.',
'constraints' => [
new NotBlank([
'message' => 'Veuillez renseigner ce champ.'
]),
new Email([
'message' => "L'e-mail '{{ value }}' n'est pas un e-mail valide."
])
]
])
->add('firstname', TextType::class, [
'required' => false,
'constraints' => [
new NotBlank([
'message' => 'Veuillez renseigner ce champ.'
])
]
])
->add('lastname', TextType::class, [
'required' => false,
'constraints' => [
new NotBlank([
'message' => 'Veuillez renseigner ce champ.'
])
]
])
->add('plainPassword', RepeatedType::class, [
'type' => PasswordType::class,
'invalid_message' => 'Les champs de mot de passe doivent correspondre.',
'required' => false,
'mapped' => false,
'attr' => ['autocomplete' => 'new-password'],
'constraints' => [
new Regex([
'pattern' => "/^(?=.{10,}$)(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*\W).*$/",
'message' => 'Le Mot de passe doit contenir au moins 10 caractères, une majuscule, un chiffre et au moins un des caractères spéciaux (!@#$%^&*-)',
]),
new NotBlank([
'message' => 'Veuillez renseigner ce champ.'
])
],
]);
}
public function configureOptions(OptionsResolver $resolver): void
{
$resolver->setDefaults([
'data_class' => User::class,
]);
}
}