示例#1
0
 /**
  * Checks the reCAPTCHA answer
  *
  * @param   string   $value  The value to check
  * @return  boolean          True if valid false otherwise
  */
 public function isValid($value)
 {
     $params = array('secret' => $this->_secretKey, 'response' => isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : '', 'remoteip' => iphorm_get_user_ip());
     $qs = http_build_query($params);
     $response = wp_remote_get('https://www.google.com/recaptcha/api/siteverify?' . $qs);
     $response = wp_remote_retrieve_body($response);
     $response = iphorm_json_decode($response, true);
     if (!is_array($response) || !isset($response['success'])) {
         $this->addMessage($this->_messageTemplates['error']);
         return false;
     }
     if (!$response['success']) {
         if (isset($response['error-codes']) && is_array($response['error-codes']) && count($response['error-codes'])) {
             foreach ($response['error-codes'] as $error) {
                 if (array_key_exists($error, $this->_messageTemplates)) {
                     $message = $this->_messageTemplates[$error];
                 } else {
                     $message = $this->_messageTemplates['invalid-input-response'];
                 }
                 $this->addMessage($message);
                 return false;
             }
         } else {
             $this->addMessage($this->_messageTemplates['error']);
             return false;
         }
     }
     return true;
 }
示例#2
0
/**
 * Verify the given purchase code
 */
function iphorm_verify_purchase_code()
{
    if ($_SERVER['REQUEST_METHOD'] == 'POST' && check_ajax_referer('iphorm_verify_purchase_code')) {
        $purchaseCode = isset($_POST['purchase_code']) && strlen($_POST['purchase_code']) ? trim($_POST['purchase_code']) : '';
        $response = array('type' => 'error', 'message' => __('An error occurred verifying the license key, please try again', 'iphorm'));
        $remoteResponse = wp_remote_post(IPHORM_API_URL . 'verify.php', array('body' => array('site_url' => site_url(), 'purchase_code' => $purchaseCode), 'timeout' => 20));
        if (wp_remote_retrieve_response_code($remoteResponse) == 200 && strlen($json = wp_remote_retrieve_body($remoteResponse))) {
            $data = iphorm_json_decode($json, true);
            if (isset($data['type'])) {
                if ($data['type'] == 'success') {
                    update_option('iphorm_licence_key', $data['licence_key']);
                    delete_transient('iphorm_latest_version_info');
                    delete_site_transient('update_plugins');
                    $response = array('type' => 'success', 'status' => 'valid', 'message' => __('License key successfully verified', 'iphorm'));
                } else {
                    if ($data['type'] == 'error' && isset($data['code'])) {
                        switch ($data['code']) {
                            case 1:
                                $response['message'] = __('Invalid license key', 'iphorm');
                                $response['status'] = 'invalid';
                                update_option('iphorm_licence_key', '');
                                break;
                            case 2:
                                $response['message'] = __('Licence key verification will be available shortly, please try again later', 'iphorm');
                                break;
                        }
                    }
                }
            }
        }
        header('Content-Type: application/json');
        echo iphorm_json_encode($response);
        exit;
    }
}