Componette

Componette

contributte

contributte / seznamcaptcha 0.5

[DISCONTINUED] Seznam captcha (security) for Nette Framework \ Forms

download-cloud-line composer require contributte/seznamcaptcha

Website ๐Ÿš€ contributte.org | Contact ๐Ÿ‘จ๐Ÿปโ€๐Ÿ’ป f3l1x.io | Twitter ๐Ÿฆ @contributte

Disclaimer

โš ๏ธ This project is no longer being maintained.
Composer contributte/seznamcaptcha
Version
PHP
License

Usage

To install latest version of contributte/seznamcaptcha use Composer.

composer require contributte/seznamcaptcha

Configuration

Extension Registration

extensions:
	captcha: Contributte\SeznamCaptcha\DI\SeznamCaptchaExtension

Options

By default is auto: on and method: http, you can disable it and bind addCaptcha to your forms by yourself.

captcha:
	auto: off # on | off
	method: xmlrpc # http | xmlrpc

Form

Just register an extension and keep auto argument as it is.

use Nette\Application\UI\Form;

protected function createComponentForm()
{
	$form = new Form();

	$form->addCaptcha('captcha')
		->setRequired('Are you robot?');

	$form->addSubmit('send');

	$form->onSuccess[] = function (Form $form) {
		dump($form['captcha']);
	};

	return $form;
}

Rendering

Automatic

{control form}

Manual

It needs a CaptchaContainer consists of 2 inputs image and code.

<form n:name="form">
    {input captcha-image}
    {input captcha-code}
</form>

Advanced Example

use Minetro\SeznamCaptcha\Forms\CaptchaHash;
use Minetro\SeznamCaptcha\Forms\CaptchaImage;
use Minetro\SeznamCaptcha\Forms\CaptchaInput;
use Minetro\SeznamCaptcha\Provider\CaptchaValidator;
use Minetro\SeznamCaptcha\Provider\ProviderFactory;
use Nette\Application\UI\Form;

/** @var ProviderFactory @inject */
public $providerFactory;

protected function createComponentForm()
{
	$form = new Form();

	$provider = $this->providerFactory->create();
	$form['image'] = new CaptchaImage('Captcha', $provider);
	$form['hash'] = new CaptchaHash($provider);
	$form['code'] = new CaptchaInput('Code');

	$form->addSubmit('send');

	$form->onValidate[] = function (Form $form) use ($provider) {
		$validator = new CaptchaValidator($provider);

		$hash = $form['hash']->getHttpHash();
		$code = $form['code']->getHttpCode();

		if ($validator->validate($code, $hash) !== TRUE) {
			$form->addError('Are you robot?');
		}
	};

	$form->onSuccess[] = function (Form $form) {
		dump($form);
	};

	return $form;
}

For better usability add this functionality to your BaseForms, BaseFormFactory or something like this. You can also create a trait for it.

Versions

State Version Branch Nette PHP
dev ^0.6 master 3.0+ >=7.2
stable ^0.5 master 3.0+ >=7.2
stable ^0.4 master 2.4+ >=5.6

Development

This package was maintained by these authors.


Consider to support contributte development team. Also thank you for using this package.

  • 0.5 v0.5

    Bumped! ๐Ÿคฆโ€โ™€๏ธ

    Diff: 0.4...0.5

    Changes:

    • PHP 8
    • Nette 3.0
    • Travis -> Github Actions
    • PHPStan v0.12
    • Readme modernize
  • 0.4 v0.4

    Bumped! ๐Ÿšถ

    Diff: 0.3...0.4

    Changes:

    • upgrade nette
    • http -> https
    • improve docs
  • 0.3 v0.3

    Bumped! ๐Ÿšถ

    Diff: 0.2...0.3

    Changes:

    • enhanced readme
    • repair validator [#1]
  • 0.2 v0.2

    Diff: 0.1...0.2

    Changes:

    • tiny typos in examples
    • fix binding bug
  • 0.1 v0.1

    First bump!

Componette Componette felix@nette.org