Ejemplo n.º 1
0
 public function __invoke(ServerRequestInterface $request, ResponseInterface $response)
 {
     $post = $request->getParsedBody();
     $gReCaptcha = empty($post['g-recaptcha-response']) ? null : $post['g-recaptcha-response'];
     $secret = empty($post['secret']) ? null : $post['secret'];
     $author = empty($post['author']) ? 'anonymous' : $post['author'];
     if (empty($post['comment'])) {
         return $response->withStatus(400, 'you have to post something...');
     }
     // validate w/ google
     if (!$this->recaptcha->IsVerified($gReCaptcha)) {
         return $response->withStatus(400, 'You did not pass re-captcha');
     }
     $comment = Comment::factory($author, $post['comment'], $secret);
     $this->entityManager->persist($comment);
     $this->entityManager->flush();
     return $response->withStatus(302, 'comment posted')->withHeader('Location', $this->router->pathFor('home'));
 }
Ejemplo n.º 2
0
 public function getNext()
 {
     return $this->hasMore() ? $this->comment->getId() - 1 : 0;
 }