【问题标题】:How can I custom password validator on sylius?如何在 sylius 上自定义密码验证器?
【发布时间】:2017-10-10 14:58:49
【问题描述】:

我想自定义用户密码的验证器。我对此进行了测试:

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

但它对我不起作用。这是我的代码:

#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]

配置:

#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

问题是当我尝试更改密码或注册时,未检测到正则表达式。我确信它可以工作,因为当我更改文件 ChangePassword.yml 时,一切正常。但我无法接触到供应商的文件。

感谢您的宝贵时间

【问题讨论】:

  • 好吧,您的正则表达式可能无法按预期工作。试试 ^(?=.*?[A-Z])(?=.*?[a-z]).{8,}$ 或者因为它是 PHP - /^(?=.*?[A-Z])(?=.*?[a-z]).{8,}$/
  • 正则表达式是正确的,我在vendor上试过,我在网上试过,不是这个问题。问题是 Sylius 没有找到覆盖文件

标签: php regex symfony validation sylius


【解决方案1】:

我找到了解决方案。我将 [myGroup] 替换为 [sylius]。

在教程中说要自定义名称,但是当我这样做时它不起作用。所以我认为我们必须把 [sylius]

【讨论】:

    猜你喜欢
    • 2015-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多