Skip to content

Commit

Permalink
Improved spam protection question updating. Now refreshes immediately…
Browse files Browse the repository at this point in the history
… after posting the form, no matter if you get it right or wrong. More consistent notification if you get the question wrong (same box used as other notifications).

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/cms/trunk@39981 467b73ca-7a2a-4603-9d3b-597d59a354a9
  • Loading branch information
Jeremy Shipman committed Aug 14, 2007
1 parent 3c4b530 commit c0f872b
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 20 deletions.
10 changes: 9 additions & 1 deletion code/sitefeatures/MathSpamProtection.php
Expand Up @@ -38,7 +38,15 @@ static function getMathQuestion(){
static function correctAnswer($answer){
$v1 = Session::get("mathQuestionV1");
$v2 = Session::get("mathQuestionV2");
return (MathSpamProtection::digitToWord($v1 + $v2) == $answer || ($v1 + $v2) == $answer) ? true : false;

Session::clear('mathQuestionV1');
Session::clear('mathQuestionV2');

if(MathSpamProtection::digitToWord($v1 + $v2) == $answer || ($v1 + $v2) == $answer){
return true;
}
return false;

}

/**
Expand Down
41 changes: 22 additions & 19 deletions code/sitefeatures/PageCommentInterface.php
Expand Up @@ -35,15 +35,11 @@ function PostCommentForm() {
new HiddenField("ParentID", "ParentID", $this->page->ID),
new TextField("Name", "Your name")
);

if(MathSpamProtection::isEnabled()){
$fields->push(new TextField("Math","Spam protection question: ".MathSpamProtection::getMathQuestion()));
}

/*//TODO
if(CaptchaSpamProtection::isEnabled()){
$fields->push(new TextField("Captcha",CaptchaSpamProtection::getImage()."<br /><br />Please copy down the text from the image above"));
} */

$fields->push(new TextareaField("Comment", "Comments"));

$form = new PageCommentInterface_Form($this->controller, $this->methodName . ".PostCommentForm",$fields, new FieldSet(
Expand Down Expand Up @@ -116,25 +112,15 @@ function postcomment($data) {
}

//check if spam question was right.
if(MathSpamProtection::isEnabled()){
if(MathSpamProtection::isEnabled()){
if(!MathSpamProtection::correctAnswer($data['Math'])){
if(Director::is_ajax()) {
echo "<div class='BlogError'><p>You got the spam protection question wrong.</p></div>";
} else {
if(!Director::is_ajax()) {
Director::redirectBack();
}
return;
return "spamprotectionfalied"; //used by javascript for checking if the spam question was wrong
}
}

/*
if(CaptchaSpamProtection::isEnabled()){
if(!CaptchaSpamProtection::correctAnswer($data['Captcha'])){
echo "<div class='BlogError'><p>You got the captcha protection question wrong.</p></div>";
return;
}
}*/

Cookie::set("PageCommentInterface_Name", $data['Name']);

$comment = Object::create('PageComment');
Expand All @@ -145,11 +131,28 @@ function postcomment($data) {
$comment->write();

if(Director::is_ajax()) {
echo $comment->renderWith('PageCommentInterface_singlecomment');
if($comment->NeedsModeration){
echo "Your comment has been submitted and is now awating moderation.";
} else{
echo $comment->renderWith('PageCommentInterface_singlecomment');
}
} else {
Director::redirectBack();
}
}
}

class PageCommentInterface_Controller extends ContentController {
function __construct() {
parent::__construct(null);
}

function newspamquestion() {
if(Director::is_ajax()) {
echo Convert::raw2xml("Spam protection question: ".MathSpamProtection::getMathQuestion());
exit;
}
}
}

?>

0 comments on commit c0f872b

Please sign in to comment.