public function testCustomAssets()
 {
     $assetsPath = __DIR__ . '/../fixture';
     $captcha = new \visualCaptcha\Captcha($this->session, $assetsPath);
     $imageOptions = $captcha->getAllImageOptions();
     $this->assertCount(2, $imageOptions);
     $this->assertEquals('Cat', $imageOptions[0]['name']);
     $audioOptions = $captcha->getAllAudioOptions();
     $this->assertCount(2, $audioOptions);
     $this->assertEquals('4plus1.mp3', $audioOptions[0]['path']);
 }
Exemple #2
0
        $app->pass();
    }
});
// Streams captcha audio from disk
// -----------------------------------------------------------------------------
// @param type is optional and defaults to 'mp3', but can also be 'ogg'
$app->get('/audio(/:type)', function ($type = 'mp3') use($app) {
    $captcha = new \visualCaptcha\Captcha($app->session);
    if (!$captcha->streamAudio($app->response, $type)) {
        $app->pass();
    }
});
// Try to validate the captcha
// -----------------------------------------------------------------------------
$app->post('/try', function () use($app) {
    $captcha = new \visualCaptcha\Captcha($app->session);
    $frontendData = $captcha->getFrontendData();
    $params = array();
    // Load the namespace into url params, if set
    if ($namespace = $app->request->params('namespace')) {
        $params[] = 'namespace=' . $namespace;
    }
    if (!$frontendData) {
        $params[] = 'status=noCaptcha';
    } else {
        // If an image field name was submitted, try to validate it
        if ($imageAnswer = $app->request->params($frontendData['imageFieldName'])) {
            if ($captcha->validateImage($imageAnswer)) {
                $params[] = 'status=validImage';
            } else {
                $params[] = 'status=failedImage';