mirror of
https://github.com/silverstripe/silverstripe-comments
synced 2024-10-22 11:05:49 +02:00
Merge pull request #166 from gordonbanderson/nonjsspamredirection
FIX: Non JS spam/ham/approve now redirect back to relevant comment
This commit is contained in:
commit
b1bf62d49c
@ -243,10 +243,7 @@ class CommentingController extends Controller {
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
|
||||
$comment->markSpam();
|
||||
|
||||
return $this->request->isAjax()
|
||||
? $comment->renderWith('CommentsInterface_singlecomment')
|
||||
: $this->redirectBack();
|
||||
return $this->renderChangedCommentState($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -261,10 +258,7 @@ class CommentingController extends Controller {
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
|
||||
$comment->markApproved();
|
||||
|
||||
return $this->request->isAjax()
|
||||
? $comment->renderWith('CommentsInterface_singlecomment')
|
||||
: $this->redirectBack();
|
||||
return $this->renderChangedCommentState($comment);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -279,10 +273,35 @@ class CommentingController extends Controller {
|
||||
if(!$comment->getSecurityToken()->checkRequest($this->request)) return $this->httpError(400);
|
||||
|
||||
$comment->markApproved();
|
||||
return $this->renderChangedCommentState($comment);
|
||||
}
|
||||
|
||||
return $this->request->isAjax()
|
||||
? $comment->renderWith('CommentsInterface_singlecomment')
|
||||
: $this->redirectBack();
|
||||
/**
|
||||
* Redirect back to referer if available, ensuring that only site URLs
|
||||
* are allowed to avoid phishing. If it's an AJAX request render the
|
||||
* comment in it's new state
|
||||
*/
|
||||
private function renderChangedCommentState($comment) {
|
||||
$referer = $this->request->getHeader('Referer');
|
||||
|
||||
// Render comment using AJAX
|
||||
if ($this->request->isAjax()) {
|
||||
return $comment->renderWith('CommentsInterface_singlecomment');
|
||||
} else {
|
||||
// Redirect to either the comment or start of the page
|
||||
if (empty($referer)) {
|
||||
return $this->redirectBack();
|
||||
} else {
|
||||
// Redirect to the comment, but check for phishing
|
||||
$url = $referer . '#comment-' . $comment->ID;
|
||||
// absolute redirection URLs not located on this site may cause phishing
|
||||
if(Director::is_site_url($url)) {
|
||||
return $this->redirect($url);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user