public function testVerifyReturnsResponse() { $method = $this->getMock('\\ReCaptcha\\RequestMethod', array('submit')); $method->expects($this->once())->method('submit')->with($this->callback(function ($params) { return true; }))->will($this->returnValue('{"success": true}')); $rc = new ReCaptcha('secret', $method); $response = $rc->verify('response'); $this->assertTrue($response->isSuccess()); }
/** * {@inheritdoc} */ public function frontend_validate(array $item, $input_value) { $mesages = array('not-configured' => __('Could not validate the form', 'fw'), 'not-human' => __('Please fill the recaptcha', 'fw')); $keys = fw_ext('forms')->get_db_settings_option('recaptcha-keys'); if (empty($keys)) { return $mesages['not-configured']; } $recaptcha = new ReCaptcha($keys['secret-key']); $gRecaptchaResponse = FW_Request::POST('g-recaptcha-response'); if (empty($gRecaptchaResponse)) { return $mesages['not-human']; } $resp = $recaptcha->verify($gRecaptchaResponse); if ($resp->isSuccess()) { return false; } else { $errors = $resp->getErrorCodes(); return $mesages['not-human']; } }
private function verify_recaptcha($client_ip, $response) { $rcmail = rcmail::get_instance(); $privatekey = $rcmail->config->get('recaptcha_privatekey'); require_once $this->home . '/lib/recaptchalib.php'; $reCaptcha = new ReCaptcha($privatekey); $resp = $reCaptcha->verify($response, $client_ip); return $resp != null && $resp->success; }
* \details Pantalla de registro en la aplicación. Añade cabeceras, muestra * los mensajes de error de action_register.php y define la estructura del layout. * \author auth.agoraUS */ require_once 'captcha/ReCaptcha.php'; require_once 'captcha/RequestMethod.php'; require_once 'captcha/RequestParameters.php'; require_once 'captcha/Response.php'; require_once 'captcha/RequestMethod/Post.php'; require_once 'captcha/RequestMethod/Socket.php'; require_once 'captcha/RequestMethod/SocketPost.php'; $clave_del_sitio = "6LfD6hcTAAAAAOLQVRMu_oJA4eCRIUxGj0tAo8HJ"; $clave_secreta = "6LfD6hcTAAAAALJdSU9xW9qZfDy0PkvcJLPs7HE4"; if ($_POST['accion'] == 'enviar') { $recaptcha = new ReCaptcha($clave_secreta); $respuesta = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); if ($respuesta->isSuccess()) { echo 'El formulario ha sido validado'; } else { echo 'Se ha devuelto el siguiente error:'; foreach ($respuesta->getErrorCodes() as $error_code) { echo '<tt>' . $error_code . '</tt> '; } } } include_once "database.php"; session_start(); ?> <!DOCTYPE html> <html lang="es" xmlns="http://www.w3.org/1999/xhtml"> <head>
private function check_captcha() { if ($this->type == 'create' && $this->captcha) { //check if capcha key is set $captcha_key = get_option('ihc_recaptcha_public'); if (!$captcha_key) { $captcha = ihc_array_value_exists($this->register_fields, 'recaptcha', 'name'); unset($this->register_fields[$captcha]); return; } $captcha = ihc_array_value_exists($this->register_fields, 'recaptcha', 'name'); if ($captcha && $this->register_fields[$captcha]['display']) { $captha_err = get_option('ihc_register_err_recaptcha'); unset($this->register_fields[$captcha]); if (isset($_REQUEST['g-recaptcha-response'])) { $secret = get_option('ihc_recaptcha_private'); if ($secret) { include_once IHC_PATH . 'classes/ReCaptcha/ReCaptcha.php'; $recaptcha = new ReCaptcha($secret); $resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']); if (!$resp->isSuccess()) { $this->errors[] = $captha_err; } } else { $this->errors[] = $captha_err; } } else { $this->errors[] = $captha_err; } } } }