Improved spam protection question updating. Now refreshes immediately 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
This commit is contained in:
Jeremy Shipman 2007-08-14 04:39:29 +00:00
parent 3c4b53030b
commit c0f872b8fe
2 changed files with 31 additions and 20 deletions

View File

@ -38,7 +38,15 @@ class MathSpamProtection {
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;
}
/**

View File

@ -35,15 +35,11 @@ class PageCommentInterface extends ViewableData {
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(
@ -116,25 +112,15 @@ class PageCommentInterface_Form extends Form {
}
//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');
@ -145,11 +131,28 @@ class PageCommentInterface_Form extends Form {
$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;
}
}
}
?>