Skip to content

replace deprecated extend of Controller by AbstractController #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Controller/CaptchaHandlerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
use Captcha\Bundle\CaptchaBundle\Support\LibraryLoader;
use Captcha\Bundle\CaptchaBundle\Helpers\BotDetectCaptchaHelper;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

class CaptchaHandlerController extends Controller
class CaptchaHandlerController extends AbstractController
{
/**
* @var object
Expand All @@ -25,7 +25,7 @@ public function indexAction()
// getting contents of css, js, and gif files.
return $this->getResourceContents();
} else {

$this->captcha = $this->getBotDetectCaptchaInstance();

if (is_null($this->captcha)) {
Expand Down
41 changes: 20 additions & 21 deletions Controller/SimpleCaptchaHandlerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@
use Captcha\Bundle\CaptchaBundle\Support\Path;
use Captcha\Bundle\CaptchaBundle\Support\SimpleLibraryLoader;
use Captcha\Bundle\CaptchaBundle\Helpers\BotDetectSimpleCaptchaHelper;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;

class SimpleCaptchaHandlerController extends Controller
class SimpleCaptchaHandlerController extends AbstractController
{
/**
* @var object
Expand All @@ -22,7 +21,7 @@ class SimpleCaptchaHandlerController extends Controller
public function indexAction()
{
$this->captcha = $this->getBotDetectCaptchaInstance();

$commandString = $this->getUrlParameter('get');
if (!\BDC_StringHelper::HasValue($commandString)) {
\BDC_HttpHelper::BadRequest('command');
Expand Down Expand Up @@ -61,7 +60,7 @@ public function indexAction()
case \BDC_SimpleCaptchaHttpCommand::GetSoundSmallDisabledIcon:
$responseBody = $this->getSmallDisabledSoundIcon();
break;

// Reload icon
case \BDC_SimpleCaptchaHttpCommand::GetReloadIcon:
$responseBody = $this->getReloadIcon();
Expand Down Expand Up @@ -106,7 +105,7 @@ private function getBotDetectCaptchaInstance()
// load BotDetect Library
$libraryLoader = new SimpleLibraryLoader($this->container);
$libraryLoader->load();

$captchaStyleName = $this->getUrlParameter('c');
if (is_null($captchaStyleName) || !preg_match('/^(\w+)$/ui', $captchaStyleName)) {
return null;
Expand Down Expand Up @@ -177,14 +176,14 @@ public function getImage()
public function getBase64ImageString()
{
header("Access-Control-Allow-Origin: *");

// authenticate client-side request
$corsAuth = new \CorsAuth();
if (!$corsAuth->IsClientAllowed()) {
\BDC_HttpHelper::BadRequest($corsAuth->GetFrontEnd() . " is not an allowed front-end");
return null;
}


// MIME type
$imageType = \ImageFormat::GetName($this->captcha->ImageFormat);
Expand All @@ -205,28 +204,28 @@ private function getImageData($p_Captcha)
if (is_null($captchaId)) {
\BDC_HttpHelper::BadRequest('Captcha Id doesn\'t exist');
}

if ($this->isObviousBotRequest($p_Captcha)) {
return;
}

// image generation invalidates sound cache, if any
$this->clearSoundData($p_Captcha, $captchaId);

// response headers
\BDC_HttpHelper::DisallowCache();

// we don't support content chunking, since image files
// are regenerated randomly on each request
header('Accept-Ranges: none');

// disallow audio file search engine indexing
header('X-Robots-Tag: noindex, nofollow, noarchive, nosnippet');

// image generation
$rawImage = $p_Captcha->CaptchaBase->GetImage($captchaId);
$p_Captcha->SaveCode($captchaId, $p_Captcha->CaptchaBase->Code); // record generated Captcha code for validation

return $rawImage;
}

Expand Down Expand Up @@ -585,22 +584,22 @@ private function getWebResource($p_Resource, $p_MimeType, $hasEtag = true)
if ($hasEtag) {
\BDC_HttpHelper::AllowEtagCache($p_Resource);
}

return file_get_contents($p_Resource);
}

private function isObviousBotRequest($p_Captcha)
{
$captchaRequestValidator = new \SimpleCaptchaRequestValidator($p_Captcha->Configuration);


// some basic request checks
$captchaRequestValidator->RecordRequest();

if ($captchaRequestValidator->IsObviousBotAttempt()) {
\BDC_HttpHelper::TooManyRequests('IsObviousBotAttempt');
}

return false;
}

Expand All @@ -619,7 +618,7 @@ private function getCaptchaId()
if (strlen($captchaId) != 32) {
return null;
}

if (1 !== preg_match(\BDC_SimpleCaptchaBase::VALID_CAPTCHA_ID, $captchaId)) {
return null;
}
Expand Down