src/Form/RegistrationFormType.php line 20

Open in your IDE?
  1. <?php
  2. namespace App\Form;
  3. use App\Entity\User;
  4. use Symfony\Component\Form\AbstractType;
  5. use Symfony\Component\Form\Extension\Core\Type\PasswordType;
  6. use Symfony\Component\Form\Extension\Core\Type\EmailType;
  7. use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
  8. use Symfony\Component\Form\Extension\Core\Type\RepeatedType;
  9. use Symfony\Component\Form\Extension\Core\Type\TextType;
  10. use Symfony\Component\Form\FormBuilderInterface;
  11. use Symfony\Component\OptionsResolver\OptionsResolver;
  12. use Symfony\Component\Validator\Constraints\NotBlank;
  13. use Symfony\Component\Validator\Constraints\Length;
  14. use Symfony\Component\Validator\Constraints\Regex;
  15. use EWZ\Bundle\RecaptchaBundle\Form\Type\EWZRecaptchaType;
  16. use EWZ\Bundle\RecaptchaBundle\Validator\Constraints\IsTrue as RecaptchaTrue;
  17. class RegistrationFormType extends AbstractType
  18. {
  19. public function buildForm(FormBuilderInterface $builder, array $options)
  20. {
  21. $builder
  22. ->add('username', TextType::class, [
  23. 'attr' => array('autofocus' => true),
  24. ])
  25. ->add('firstname')
  26. ->add('lastname')
  27. ->add('email', EmailType::class, [
  28. 'attr' => array('autofocus' => false),
  29. ])
  30. ->add('plainPassword', RepeatedType::class, array(
  31. 'type' => PasswordType::class,
  32. 'invalid_message' => 'Podane hasła muszą być takie same',
  33. 'required' => true,
  34. 'mapped' => false,
  35. 'constraints' => [
  36. new NotBlank([
  37. 'message' => 'Hasło musi zawierać min 8 znaków',
  38. ]),
  39. new Length([
  40. 'min' => 8,
  41. 'minMessage' => 'Hasło musi zawierać min 8 znaków',
  42. // max length allowed by Symfony for security reasons
  43. 'max' => 64,
  44. ]),
  45. new Regex([
  46. 'pattern' => '/^(?=.{8,}$)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?\W).*$/',
  47. 'message' => 'Hasło musi zawierać conajmiej 8 znaków, w tym jedna duża litera, jedna cyfra i jeden znak specjalny ',
  48. ])
  49. //^(?=.{8,}$)(?=.*?[a-z])(?=.*?[A-Z])(?=.*?[0-9])(?=.*?\W).*$
  50. ],
  51. ))
  52. ->add('rules', CheckboxType::class, [
  53. 'mapped' => false,
  54. ]);
  55. }
  56. public function configureOptions(OptionsResolver $resolver)
  57. {
  58. $resolver->setDefaults([
  59. 'data_class' => User::class,
  60. // enable/disable CSRF protection for this form
  61. 'csrf_protection' => true,
  62. // the name of the hidden HTML field that stores the token
  63. 'csrf_field_name' => '_token',
  64. // an arbitrary string used to generate the value of the token
  65. // using a different string for each form improves its security
  66. 'csrf_token_id' => 'registration',
  67. ]);
  68. }
  69. }