Create an option for enabling/disabling numeric answers (solution to issue #19)
Some spam bots input randomized numbers to the MathSpamProtectorField which some times happen to be correct and let spam come through. This option makes it possible to accept only verbal answers. This commit won't change the default behavior, so in order to disable numeric answers, put this to your yml file: MathSpamProtectorField: allow_numeric_answer: false
This commit is contained in:
parent
1fd4a0c693
commit
c83e2935b7
|
@ -14,6 +14,20 @@ class MathSpamProtectorField extends TextField {
|
|||
* @var bool $enabled
|
||||
*/
|
||||
private static $enabled = true;
|
||||
|
||||
/**
|
||||
* @config
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
private static $question_prefix;
|
||||
|
||||
/**
|
||||
* @config
|
||||
*
|
||||
* @var bool $allow_numeric_answer
|
||||
*/
|
||||
private static $allow_numeric_answer = true;
|
||||
|
||||
public function Field($properties = array()) {
|
||||
if(Config::inst()->get('MathSpamProtectorField', 'enabled')) {
|
||||
|
@ -37,8 +51,14 @@ class MathSpamProtectorField extends TextField {
|
|||
* @return string
|
||||
*/
|
||||
public function Title() {
|
||||
$prefix = Config::inst()->get('MathSpamProtection', 'question_prefix');
|
||||
|
||||
if(!$prefix) {
|
||||
$prefix = _t('MathSpamProtectionField.SPAMQUESTION', "Spam protection question: %s");
|
||||
}
|
||||
|
||||
return sprintf(
|
||||
_t('MathSpamProtectionField.SPAMQUESTION', "Spam protection question: %s"),
|
||||
$prefix,
|
||||
self::get_math_question()
|
||||
);
|
||||
}
|
||||
|
@ -113,7 +133,8 @@ class MathSpamProtectorField extends TextField {
|
|||
|
||||
$word = MathSpamProtectorField::digit_to_word($v1 + $v2);
|
||||
|
||||
return ($word == strtolower($answer) || ($v1 + $v2) == $answer);
|
||||
$allow_numeric_answer = Config::inst()->get('MathSpamProtectorField', 'allow_numeric_answer');
|
||||
return ($word == strtolower($answer) || ((($v1 + $v2) == $answer) and $allow_numeric_answer));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -146,4 +167,8 @@ class MathSpamProtectorField extends TextField {
|
|||
|
||||
return $numbers[$num];
|
||||
}
|
||||
|
||||
public function Type() {
|
||||
return 'mathspamprotector text';
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue