如何在Concrete5.7中自定义SecurimageController

时间:2015-06-02 13:18:08

标签: php captcha concrete5-5.7

我的联系表格中有一个系统Captcha,它可以自行运行。

在此之后:https://github.com/concrete5/concrete5/issues/2088 - 一切正常。但是在此之后:https://www.concrete5.org/documentation/developers/5.7/packages/adding-custom-code-to-packages/ - 不起作用。这是我的文件:

包/ my_package / Controller.php这样:

<?php        
namespace Concrete\Package\MyPackage;
use Package;
use BlockType;

defined('C5_EXECUTE') or die(_("Access Denied."));

class Controller extends Package {

    protected $pkgHandle = 'my_package';
    protected $appVersionRequired = '5.7.1';
    protected $pkgVersion = '0.1';
    protected $pkgAutoloaderMapCoreExtensions = true;

    public function getPackageDescription() {
        return t('Contact Form');
    }

    public function getPackageName() {
        return t("Contact Form");
    }

    public function install() {
        $pkg = parent::install();
        BlockType::installBlockTypeFromPackage('my_package', $pkg);
    }
}

包/ my_package / SRC /混凝土/验证码/ MySecurimageController.php:

<?php
namespace Concrete\Package\MyPackage\Captcha;

use Securimage;
use Securimage_Color;

class SecurimageController extends \Concrete\Core\Captcha\SecurimageController
{
    protected $securimage;

    public function __construct()
    {
    $this->securimage = new Securimage();
    $this->securimage->image_width = 237;
    $this->securimage->image_height = 60;
    $this->securimage->image_bg_color = new Securimage_Color('#F0F0F0');
    $this->securimage->line_color = new Securimage_Color('#333333');

    $this->securimage->use_multi_text = true;
    $this->securimage->multi_text_color = array(
        new Securimage_Color('#FF0000'),
        new Securimage_Color('#0000FF'),
        new Securimage_Color('#333333')
    );
    $this->securimage->text_color = new Securimage_Color('#FF0000');
    $this->securimage->use_transparent_text = true;
    $this->securimage->text_transparency_percentage = 50;

    $this->securimage->image_signature = 'MY_DOMAIN';
    $this->securimage->signature_color = new Securimage_Color('#333333');
    $this->securimage->code_length = rand(4, 6);
    $this->securimage->num_lines = rand(3, 10);

    }
}

包/ my_package /块/ my_package / Controller.php这样:

$captcha = Loader::helper('validation/captcha');
if (!$captcha->check('code')) {
    $this->errors['code'] = $this->error_code;
}

包/ my_package /块/ my_package / view.php:

    <?php 
    $captcha = Loader::helper('validation/captcha');
    $captcha->display(); 
    ?>
    <input type="text" id="code" name="code" value="<?php echo $code; ?>" maxlength="6" />

我错过了什么?

非常感谢。

0 个答案:

没有答案