简体   繁体   English

ZFCUser中的用户名/密码字段验证的将来打样更改

[英]Future Proofing Changes to Validation of Username/Password Field in ZFCUser

I've been looking around at how to change the actual validation process of the registration fields in the ZFCUser module in Zend Framework 2. 我一直在寻找如何更改Zend Framework 2中ZFCUser模块中注册字段的实际验证过程。

There is a lot about extending and adding new fields etc. to the form but not validating these fields or extending the existing validation. 有很多关于扩展和添加新字段等到表单,但不验证这些字段或扩展现有验证的方法。

I have taken a look inside the code and found the RegistrationForm.php file and added my customer Regular Expression filters. 我看了一下代码内部,发现了RegistrationForm.php文件,并添加了我的客户正则表达式过滤器。

This works well and as expected but I am worried about this being over-written on any future upgrade. 效果很好,符合预期,但我担心在以后的任何升级中都将其覆盖。

How would I go about doing this so it is upgrade safe? 我将如何进行操作以确保升级安全? Is it a case of extending a specific class or adding it as a local file in my custom modules as I have done with the view files. 是否像我对视图文件所做的那样,扩展特定类或将其添加为自定义模块中的本地文件。

I've same problem as you, and also do not find proper solution. 我和您有同样的问题,也找不到合适的解决方案。 But IMHO better way than change original source code is to override one of the ZfcUser services. 但是,恕我直言,比更改原始源代码更好的方法是重写ZfcUser服务之一。

There is a service called 'zfcuser_change_password_form' defined in zfc-user Module.php. 在zfc-user Module.php中定义了一个名为“ zfcuser_change_password_form”的服务。 If you create own service with same name - the original one will be overriden. 如果您使用相同的名称创建自己的服务-原始服务将被覆盖。 So, first you need to define your own filter / validator class (YourFilter), then in your Module.php add: 因此,首先需要定义自己的过滤器/验证器类(YourFilter),然后在Module.php中添加:

public function getServiceConfig()
{
    return array(
        // ...
        'factories' => array(
            // ... 
            'zfcuser_change_password_form' => function ($sm) {
                $options = $sm->get('zfcuser_module_options');
                $form = new \ZfcUser\Form\ChangePassword(
                       null, $sm->get('zfcuser_module_options')
                    );
                $form->setInputFilter(
                       new \YourModule\Form\YourFilter($options)
                    );
                return $form;
            },
        ),
    );
}

Such solution allows to update zfcuser without overriding your changes. 这种解决方案允许更新zfcuser,而不会覆盖您的更改。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM