Captcha en lettres + correction du nom : capcha en captcha

This commit is contained in:
Fred Tempez 2020-08-10 19:07:17 +02:00
parent bf1819fc74
commit e94cb81b24
7 changed files with 23 additions and 21 deletions

View File

@ -33,12 +33,12 @@ class template {
}
/**
* Crée un champ capcha
* Crée un champ captcha
* @param string $nameId Nom et id du champ
* @param array $attributes Attributs ($key => $value)
* @return string
*/
public static function capcha($nameId, array $attributes = []) {
public static function captcha($nameId, array $attributes = []) {
// Attributs par défaut
$attributes = array_merge([
'class' => '',
@ -48,13 +48,15 @@ class template {
'name' => $nameId,
'value' => ''
], $attributes);
// Génère deux nombres pour le capcha
$firstNumber = mt_rand(1, 15);
$secondNumber = mt_rand(1, 15);
// Génère deux nombres pour le captcha
$numbers=array(0,1,2,3,4,5,6,7,8,9,10,12,13,14,15,16,17,18,19,20);
$letters=array('zéro','un','deux','trois','quatre','cinq','six','sept','huit','neuf','dix','onze','douze','treize','quatorze','quinze','seize','dix-sept','dix-huit','dix-neuf','vingt');
$firstNumber=rand ( 0 , count($letters)-1 );
$secondNumber=rand ( 0 , count($letters)-1 );
// Début du wrapper
$html = '<div id="' . $attributes['id'] . 'Wrapper" class="inputWrapper ' . $attributes['classWrapper'] . '">';
// Label
$html .= self::label($attributes['id'], $firstNumber . ' + ' . $secondNumber . ' = ?', [
$html .= self::label($attributes['id'], $letters[$firstNumber] . ' + ' . $letters[$secondNumber] . ' = ? (réponse en chiffres)', [
'help' => $attributes['help']
]);
// Notice
@ -64,7 +66,7 @@ class template {
$attributes['class'] .= ' notice';
}
$html .= self::notice($attributes['id'], $notice);
// Capcha
// captcha
$html .= sprintf(
'<input type="text" %s>',
helper::sprintAttributes($attributes)

View File

@ -632,7 +632,7 @@ class init extends common {
'contact' => [
'config' => [
'button' => '',
'capcha' => true,
'captcha' => true,
'group' => self::GROUP_ADMIN,
'pageId' => '',
'subject' => ''

View File

@ -339,12 +339,12 @@ class blog extends common {
else {
// Soumission du formulaire
if($this->isPost()) {
// Check la capcha
// Check la captcha
if(
$this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')
AND $this->getInput('blogArticleCapcha', helper::FILTER_INT) !== $this->getInput('blogArticleCapchaFirstNumber', helper::FILTER_INT) + $this->getInput('blogArticleCapchaSecondNumber', helper::FILTER_INT))
AND $this->getInput('blogArticlecaptcha', helper::FILTER_INT) !== $this->getInput('blogArticlecaptchaFirstNumber', helper::FILTER_INT) + $this->getInput('blogArticlecaptchaSecondNumber', helper::FILTER_INT))
{
self::$inputNotices['blogArticleCapcha'] = 'Incorrect';
self::$inputNotices['blogArticlecaptcha'] = 'Incorrect';
}
// Crée le commentaire
$commentId = helper::increment(uniqid(), $this->getData(['module', $this->getUrl(0), $this->getUrl(1), 'comment']));

View File

@ -75,7 +75,7 @@
<?php if($this->getUser('password') !== $this->getInput('ZWII_USER_PASSWORD')): ?>
<div class="row">
<div class="col4">
<?php echo template::capcha('blogArticleCapcha'); ?>
<?php echo template::captcha('blogArticlecaptcha'); ?>
</div>
</div>
<?php endif; ?>

View File

@ -77,7 +77,7 @@ class form extends common {
'config',
[
'button' => $this->getInput('formConfigButton'),
'capcha' => $this->getInput('formConfigCapcha', helper::FILTER_BOOLEAN),
'captcha' => $this->getInput('formConfigcaptcha', helper::FILTER_BOOLEAN),
'group' => $this->getInput('formConfigGroup', helper::FILTER_INT),
'user' => self::$listUsers [$this->getInput('formConfigUser', helper::FILTER_INT)],
'mail' => $this->getInput('formConfigMail') ,
@ -279,12 +279,12 @@ class form extends common {
public function index() {
// Soumission du formulaire
if($this->isPost()) {
// Check la capcha
// Check la captcha
if(
$this->getData(['module', $this->getUrl(0), 'config', 'capcha'])
AND $this->getInput('formCapcha', helper::FILTER_INT) !== $this->getInput('formCapchaFirstNumber', helper::FILTER_INT) + $this->getInput('formCapchaSecondNumber', helper::FILTER_INT))
$this->getData(['module', $this->getUrl(0), 'config', 'captcha'])
AND $this->getInput('formcaptcha', helper::FILTER_INT) !== $this->getInput('formcaptchaFirstNumber', helper::FILTER_INT) + $this->getInput('formcaptchaSecondNumber', helper::FILTER_INT))
{
self::$inputNotices['formCapcha'] = 'Incorrect';
self::$inputNotices['formcaptcha'] = 'Incorrect';
}
// Préparation le contenu du mail

View File

@ -142,8 +142,8 @@
]); ?>
</div>
</div>
<?php echo template::checkbox('formConfigCapcha', true, 'Valider un capcha afin de soumettre le formulaire.', [
'checked' => $this->getData(['module', $this->getUrl(0), 'config', 'capcha'])
<?php echo template::checkbox('formConfigcaptcha', true, 'Valider un captcha afin de soumettre le formulaire.', [
'checked' => $this->getData(['module', $this->getUrl(0), 'config', 'captcha'])
]); ?>
</div>
<div class="block">

View File

@ -43,10 +43,10 @@
</h3>
<?php endif; ?>
<?php endforeach; ?>
<?php if($this->getData(['module', $this->getUrl(0), 'config', 'capcha'])): ?>
<?php if($this->getData(['module', $this->getUrl(0), 'config', 'captcha'])): ?>
<div class="row">
<div class="col4">
<?php echo template::capcha('formCapcha'); ?>
<?php echo template::captcha('formcaptcha'); ?>
</div>
</div>
<?php endif; ?>