You are here

public function CaptchaImageResponse::prepare in CAPTCHA 8

File

image_captcha/src/Response/CaptchaImageResponse.php, line 71

Class

CaptchaImageResponse
Response which is returned as the captcha for image_captcha.

Namespace

Drupal\image_captcha\Response

Code

public function prepare(Request $request) {
  $session_id = $request
    ->get('session_id');
  $code = $this->connection
    ->select('captcha_sessions', 'cs')
    ->fields('cs', [
    'solution',
  ])
    ->condition('csid', $session_id)
    ->execute()
    ->fetchField();
  if ($code !== FALSE) {
    $this->image = @$this
      ->generateImage($code);
    if (!$this->image) {
      $this->logger
        ->log(self::LOG_LEVEL, 'Generation of image CAPTCHA failed. Check your image CAPTCHA configuration and especially the used font.', []);
    }
  }
  return parent::prepare($request);
}