From 2bcf0ec30ed809b7f6aa896e67c45a8168e87f27 Mon Sep 17 00:00:00 2001 From: Juan van den Anker Date: Fri, 2 Jun 2017 10:47:49 +1200 Subject: [PATCH] FIX endless redirect while moderating comments --- code/controllers/CommentingController.php | 36 +++++++++++++++++++++-- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/code/controllers/CommentingController.php b/code/controllers/CommentingController.php index 72fdab9..d00bfbb 100644 --- a/code/controllers/CommentingController.php +++ b/code/controllers/CommentingController.php @@ -263,7 +263,17 @@ class CommentingController extends Controller return $this->httpError(400); } - $comment->markSpam(); + if (!$comment->Moderated) { + $comment->markSpam(); + } + + // prevent endless loop of redirects if this request has been made without being logged on + $referer = $this->request->getHeader('Referer'); + if (strpos($referer,"/Security/login") !== false) { + echo "Comment marked as spam"; + return ; + } + return $this->renderChangedCommentState($comment); } @@ -283,7 +293,17 @@ class CommentingController extends Controller return $this->httpError(400); } - $comment->markApproved(); + if (!$comment->Moderated) { + $comment->markApproved(); + } + + // prevent endless loop of redirects if this request has been made without being logged on + $referer = $this->request->getHeader('Referer'); + if (strpos($referer,"/Security/login") !== false) { + echo "Comment approved"; + return ; + } + return $this->renderChangedCommentState($comment); } @@ -303,7 +323,17 @@ class CommentingController extends Controller return $this->httpError(400); } - $comment->markApproved(); + if (!$comment->Moderated) { + $comment->markApproved(); + } + + // prevent endless loop of redirects if this request has been made without being logged on + $referer = $this->request->getHeader('Referer'); + if (strpos($referer,"/Security/login") !== false) { + echo "Comment approved"; + return ; + } + return $this->renderChangedCommentState($comment); }