replace antispam question and answer with numeral captcha

This commit is contained in:
Christian Weiske 2010-05-26 19:14:53 +02:00
parent f4c51ccb4e
commit 362d159437
3 changed files with 17 additions and 46 deletions

View File

@ -237,31 +237,6 @@ $adminsAreAdvisedTagsFromOtherAdmins = false;
*/
$reservedusers = array('all', 'watchlist');
/***************************************************
* Anti SPAM measures
*/
/**
* A question to avoid spam.
* Shown on user registration page.
*
* @var string
* @see $antispamAnswer
*/
$antispamQuestion = 'name of this application';
/**
* The answer to the antispam question
* Users have to write exactly this string.
*
* @var string
* @see $antispamQuestion
*/
$antispamAnswer = 'semanticscuttle';
/**
* Enable or disable user registration
*

View File

@ -29,10 +29,10 @@ window.onload = function() {
<td><?php echo '←'.T_(' to send you your password if you forget it')?></td>
</tr>
<?php if (isset($form['antispamAnswer'])) {?>
<?php if (isset($form['captcha'])) {?>
<tr>
<th align="left"><?php echo $form['antispamAnswer']['labelhtml']; ?></label></th>
<td><?php echo $form['antispamAnswer']['html']; ?></td>
<th align="left"><?php echo $form['captcha']['labelhtml']; ?></label></th>
<td><?php echo $form['captcha']['html']; ?></td>
<td></td>
</tr>
<?php } ?>

View File

@ -30,11 +30,19 @@ if (!$GLOBALS['enableRegistration']) {
require_once 'HTML/QuickForm2.php';
require_once 'HTML/QuickForm2/Renderer.php';
require_once 'HTML/QuickForm2/Element/BackgroundText.php';
require_once 'HTML/QuickForm2/Element/NumeralCaptcha.php';
HTML_QuickForm2_Factory::registerElement(
'backgroundtext',
'HTML_QuickForm2_Element_BackgroundText'
);
//we register a strange name here so we can change the class
// itself easily
HTML_QuickForm2_Factory::registerElement(
'sc-captcha',
'HTML_QuickForm2_Element_NumeralCaptcha'
);
$form = new HTML_QuickForm2(
'registration', 'post',
@ -104,34 +112,22 @@ $email->addRule(
);
$form->addElement(
'backgroundtext', 'antispamAnswer',
'sc-captcha', 'captcha',
array(
'id' => 'antispamAnswer',
'id' => 'captcha',
'size' => 40
),
array(
'captchaSolutionWrong' => T_('Antispam answer is not valid. Please try again.')
)
)
->setLabel(T_('Antispam question'))
->setBackgroundText($GLOBALS['antispamQuestion'])
->setBackgroundClass('inacttext')
->addRule(
'callback',
T_('Antispam answer is not valid. Please try again.'),
'verifyAntiSpamAnswer'
);
//FIXME: custom rule or captcha element
->setLabel(T_('Antispam question'));
$form->addElement(
'submit', 'submitted', array('id' => 'submit')
)
->setLabel(T_('Register'));
function verifyAntiSpamAnswer($userAnswer)
{
return strcasecmp(
str_replace(' ', '', $userAnswer),
str_replace(' ', '', $GLOBALS['antispamAnswer'])
) == 0;
}
$tplVars['error'] = '';
if ($form->validate()) {