fix errors when creating user and updating password

This commit is contained in:
2018-09-04 16:55:34 +02:00
parent 04bdaa308a
commit e88265adcd
4 changed files with 46 additions and 18 deletions

View File

@@ -6,6 +6,11 @@ use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolver;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
use Symfony\Component\Validator\Constraints\Length;
use Symfony\Component\Validator\Constraints\NotBlank;
use Symfony\Component\Validator\Constraints\Regex;
use Symfony\Component\Form\Extension\Core\Type\PasswordType;
use Chill\MainBundle\Form\UserPasswordType;
@@ -22,8 +27,31 @@ class UserType extends AbstractType
->add('email')
;
if ($options['is_creation']) {
$builder->add('plainPassword', UserPasswordType::class, array(
'mapped' => false
$builder->add('plainPassword', RepeatedType::class, array(
'mapped' => false,
'type' => PasswordType::class,
'required' => false,
'options' => array(),
'first_options' => array(
'label' => 'Password'
),
'second_options' => array(
'label' => 'Repeat the password'
),
'invalid_message' => "The password fields must match",
'constraints' => array(
new Length(array(
'min' => 9,
'minMessage' => 'The password must be greater than {{ limit }} characters'
)),
new NotBlank(),
new Regex(array(
'pattern' => "/((?=.*\d)(?=.*[a-z])(?=.*[A-Z])(?=.*[@#$%!,;:+\"'-\/{}~=µ\(\)£]).{6,})/",
'message' => "The password must contains one letter, one "
. "capitalized letter, one number and one special character "
. "as *[@#$%!,;:+\"'-/{}~=µ()£]). Other characters are allowed."
))
)
));
} else {