phpregexsymfonyvalidationsylius

How can I custom password validator on sylius?


I'd like to custom the validators of users' password. I tested this :

http://sylius-try.readthedocs.io/en/latest/bundles/general/overriding_validation.html

http://sylius-older.readthedocs.io/en/latest/customization/validation.html

http://docs.sylius.org/en/latest/customization/validation.html

However it doesn't work for me.This is my code :

#AppBundle/Resources/config/validation.yml

Sylius\Bundle\UserBundle\Form\Model\ChangePassword:
    properties:
        currentPassword:
            - Symfony\Component\Security\Core\Validator\Constraints\UserPassword:
                message: sylius.user.plainPassword.wrong_current
                groups: [myGroup]
        newPassword:
            - Regex:
                pattern: ((?=\S*?[A-Z])(?=\S*?[a-z]).{8,})
                message: myGroup.user.password.regex
                groups: [myGroup]

Config :

#app/config/config.yml   
 imports:
    - { resource: "@SyliusCoreBundle/Resources/config/app/config.yml" }

Services.yml :

# app/config/services.yml
parameters:
    sylius.form.type.user_change_password: [myGroup]
    sylius.form.type.user_reset_password.validation_groups: [myGroup] # the product class also needs to be aware of the translation'a validation

The problem is that when I'm trying to change the password or to register, the regex is not detect. I'm sure that it works because when I change the files ChangePassword.yml, everything works. But I can't touch to the vendor's files.

Thanks for your time


Solution

  • I found a solution. I replaced [myGroup] by [sylius].

    In the tutorial it's say to custom the name, however when I did it it didn't work. So I think we have to put [sylius]