Skip to content
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

WP Enforcer & Auto Fixes #79

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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,6 @@ pip-log.txt

#Composer
composer.json


vendor/*
153 changes: 153 additions & 0 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

117 changes: 59 additions & 58 deletions includes/ReCaptcha/ReCaptcha.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,70 +29,71 @@
/**
* reCAPTCHA client.
*/
class ReCaptcha
{
/**
* Version of this client library.
* @const string
*/
const VERSION = 'php_1.1.2';
class ReCaptcha {

/**
* Shared secret for the site.
* @var string
*/
private $secret;
/**
* Version of this client library.
*
* @const string
*/
const VERSION = 'php_1.1.2';

/**
* Method used to communicate with service. Defaults to POST request.
* @var RequestMethod
*/
private $requestMethod;
/**
* Shared secret for the site.
*
* @var string
*/
private $secret;

/**
* Create a configured instance to use the reCAPTCHA service.
*
* @param string $secret shared secret between site and reCAPTCHA server.
* @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
* @throws \RuntimeException if $secret is invalid
*/
public function __construct($secret, RequestMethod $requestMethod = null)
{
if (empty($secret)) {
throw new \RuntimeException('No secret provided');
}
/**
* Method used to communicate with service. Defaults to POST request.
*
* @var RequestMethod
*/
private $requestMethod;

if (!is_string($secret)) {
throw new \RuntimeException('The provided secret must be a string');
}
/**
* Create a configured instance to use the reCAPTCHA service.
*
* @param string $secret shared secret between site and reCAPTCHA server.
* @param RequestMethod $requestMethod method used to send the request. Defaults to POST.
* @throws \RuntimeException if $secret is invalid
*/
public function __construct( $secret, RequestMethod $requestMethod = null ) {
if ( empty( $secret ) ) {
throw new \RuntimeException( 'No secret provided' );
}

$this->secret = $secret;
if ( ! is_string( $secret ) ) {
throw new \RuntimeException( 'The provided secret must be a string' );
}

if (!is_null($requestMethod)) {
$this->requestMethod = $requestMethod;
} else {
$this->requestMethod = new RequestMethod\Post();
}
}
$this->secret = $secret;

/**
* Calls the reCAPTCHA siteverify API to verify whether the user passes
* CAPTCHA test.
*
* @param string $response The value of 'g-recaptcha-response' in the submitted form.
* @param string $remoteIp The end user's IP address.
* @return Response Response from the service.
*/
public function verify($response, $remoteIp = null)
{
// Discard empty solution submissions
if (empty($response)) {
$recaptchaResponse = new Response(false, array('missing-input-response'));
return $recaptchaResponse;
}
if ( ! is_null( $requestMethod ) ) {
$this->requestMethod = $requestMethod;
} else {
$this->requestMethod = new RequestMethod\Post();
}
}

$params = new RequestParameters($this->secret, $response, $remoteIp, self::VERSION);
$rawResponse = $this->requestMethod->submit($params);
return Response::fromJson($rawResponse);
}
/**
* Calls the reCAPTCHA siteverify API to verify whether the user passes
* CAPTCHA test.
*
* @param string $response The value of 'g-recaptcha-response' in the submitted form.
* @param string $remoteIp The end user's IP address.
* @return Response Response from the service.
*/
public function verify( $response, $remoteIp = null ) {
// Discard empty solution submissions
if ( empty( $response ) ) {
$recaptchaResponse = new Response( false, array( 'missing-input-response' ) );
return $recaptchaResponse;
}

$params = new RequestParameters( $this->secret, $response, $remoteIp, self::VERSION );
$rawResponse = $this->requestMethod->submit( $params );
return Response::fromJson( $rawResponse );
}
}
18 changes: 9 additions & 9 deletions includes/ReCaptcha/RequestMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
/**
* Method used to send the request to the service.
*/
interface RequestMethod
{
interface RequestMethod {

/**
* Submit the request with the specified parameters.
*
* @param RequestParameters $params Request parameters
* @return string Body of the reCAPTCHA response
*/
public function submit(RequestParameters $params);

/**
* Submit the request with the specified parameters.
*
* @param RequestParameters $params Request parameters
* @return string Body of the reCAPTCHA response
*/
public function submit( RequestParameters $params);
}
Loading