Exemple #1
0
 /**
  * @param $args
  * GET: /misc/captcha
  */
 public function captcha($args)
 {
     $letters = 'qwertyuiopasdfghjklzxcvbnm1234567890';
     $captchaLen = 6;
     $width = 120;
     $height = 30;
     $font = $_SERVER['DOCUMENT_ROOT'] . Config::$SUB_FOLDER . "/content/fonts/consolas.ttf";
     $fontSize = 16;
     header('Content-type: image/png');
     $image = imagecreatetruecolor($width, $height);
     imagesavealpha($image, true);
     $bg = imagecolorallocate($image, 190, 190, 190);
     imagefill($image, 0, 0, $bg);
     $captcha = '';
     for ($i = 0; $i < $captchaLen; $i++) {
         $captcha .= $letters[rand(0, strlen($letters) - 1)];
         $x = ($width - 20) / $captchaLen * $i + 10;
         $x = rand($x, $x + 4);
         $y = $height - ($height - $fontSize) / 2;
         $curColor = imagecolorallocate($image, 255, 255, 255);
         //rand(0, 100), rand(0, 100), rand(0, 100));
         $angle = rand(-25, 25);
         imagettftext($image, $fontSize, $angle, $x, $y, $curColor, $font, $captcha[$i]);
     }
     Captcha::setCaptcha($args[0], $captcha);
     imagepng($image);
     imagedestroy($image);
 }
Exemple #2
0
 /**
  * POST: /main/create-comment
  */
 public function createCommentPost()
 {
     $pageId = $_REQUEST['PageId'];
     $commentId = $_REQUEST['CommentId'];
     $body = $_REQUEST['Body'];
     $pageDAO = new PageDAO();
     $page = $pageDAO->getPage($pageId);
     if ($page->feedbackType != PageEntity::$FEEDBACK_COMMENTS_AUTH || Authentication::isAuthenticated()) {
         $captcha = true;
         if ($page->feedbackType == PageEntity::$FEEDBACK_COMMENTS_CAPTCHA && !Authentication::isAuthenticated()) {
             $captcha = Captcha::getCaptcha($commentId) == $_REQUEST['Captcha'];
         }
         if ($captcha) {
             $commentId = $commentId == 0 ? null : $commentId;
             $browsingId = Browsing::getBrowsingId();
             $userId = Authentication::isAuthenticated() ? Authentication::getUserEntity()->id : null;
             $commentOnPageDAO = new CommentOnPageDAO();
             $newCommentId = $commentOnPageDAO->createCommentOnPage($pageId, $commentId, $browsingId, $userId, $body);
             $newComment = $commentOnPageDAO->getCommentOnPage($newCommentId);
             echo CommentOnPageHelper::comment($newComment, $page->feedbackType);
         } else {
             echo 'captcha';
         }
     }
 }