Zend Framework 2: How to properly replace Figlet with reCaptcha on zfcUser

笑着哭i 提交于 2019-12-05 16:06:37

This is how I did it, it might not be the best or correct way but it worked for me:

Add the recaptcha service to your composer.json file:

"require": {
    "Zendframework/zendservice-recaptcha": "2.*"
}

Run composer to get the service. Then you need to specify the ReCaptcha config. I created a separate config file to store the ReCaptcha keys:

//zfcuser.local.php
return array(
    'zfcuser' => array(
        'form_captcha_options' => array(
            'options' => array(
                'privkey' => RECAPTCHA_PRIVATE_KEY,   
                'pubkey'  => RECAPTCHA_PUBLIC_KEY,
            ),
        ),
    ),
); 

Then ZfcUser captcha config looks like so, telling it to use the ReCaptcha service:

//zfcuser.global.php
'form_captcha_options' => array(
    'class'   => 'Zend\Captcha\ReCaptcha',
    'options' => array(
        'wordLen'    => 6,
        'expiration' => 300,
        'timeout'    => 300,
     ),
),

Edit:

You don't need the recaptcha.global.php. You can call the config file whatever you like aslong as it ends with .global.php or .local.php. You usually name things .local.php when you don't want them in version control.

In this case I named the file zfcuser.local.php because all it does is store the ReCaptcha keys and I didn't want them in version control.

All the config files get merged in to one array when the application is started. So basically, ignore the ZfcUser documentation. Or maybe someone else can explain how to get it working that way.

The third block of code is the zfcuser.global.php.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!