[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/pkg/vtiger/modules/Webforms/settings/actions/ -> CheckCaptcha.php (source)

   1  <?php
   2  /*+**********************************************************************************

   3   * The contents of this file are subject to the vtiger CRM Public License Version 1.1

   4   * ("License"); You may not use this file except in compliance with the License

   5   * The Original Code is:  vtiger CRM Open Source

   6   * The Initial Developer of the Original Code is vtiger.

   7   * Portions created by vtiger are Copyright (C) vtiger.

   8   * All Rights Reserved.

   9   ************************************************************************************/
  10  
  11  // Switch the working directory to base

  12  chdir(dirname(__FILE__) . '/../../../..');
  13  
  14  include_once  'includes/http/Response.php';
  15  include_once  'vtlib/Vtiger/Module.php';
  16  include_once  'include/utils/VtlibUtils.php';
  17  include_once  'include/recaptcha/recaptchalib.php';
  18  include_once 'modules/Webforms/config.captcha.php';
  19  
  20  class Webform_CheckCaptcha {
  21      
  22      protected $PUBLIC_KEY = false;
  23      protected $PRIVATE_KEY = false;
  24      
  25      /**

  26       * Function to intialize captch keys

  27       */
  28      function __construct() {
  29          global $captchaConfig;
  30          $this->PUBLIC_KEY = $captchaConfig['VTIGER_RECAPTCHA_PUBLIC_KEY'];
  31          $this->PRIVATE_KEY = $captchaConfig['VTIGER_RECAPTCHA_PRIVATE_KEY'];
  32      }
  33  
  34  	function checkCaptchaNow($request) {
  35  
  36          // to store the response from reCAPTCHA

  37          $resp = null;
  38  
  39          if ($request["recaptcha_response_field"]) {
  40                  $resp = recaptcha_check_answer ($this->PRIVATE_KEY,
  41                                                  $_SERVER["REMOTE_ADDR"],
  42                                                  $request["recaptcha_challenge_field"],
  43                                                  $request["recaptcha_response_field"]);
  44  
  45                  if ($resp->is_valid) {
  46                          $this->sendResponse(true, $request['callId']);
  47                  } else {
  48                          $this->sendResponse(false, $request['callId']);
  49                  }
  50          } else {
  51              $this->sendResponse(false, $request['callId']);
  52          }
  53      }
  54  
  55  	protected function sendResponse($success, $callId) {
  56          $response = new Vtiger_Response();
  57          if ($success)
  58              $response->setResult(array('success' => true, 'callId' => $callId));
  59          else
  60              $response->setResult(array('success' => false, 'callId' => $callId));
  61  
  62          // Support JSONP

  63          if (!empty($_REQUEST['callback'])) {
  64              $callback = vtlib_purify($_REQUEST['callback']);
  65              $response->setEmitType('4');
  66              $response->setEmitJSONP($callback);
  67              $response->emit();
  68          } else {
  69              $response->emit();
  70          }
  71      }
  72  }
  73  
  74  $webformCheckCaptcha = new Webform_CheckCaptcha;
  75  $webformCheckCaptcha->checkCaptchaNow(vtlib_purify($_REQUEST));
  76  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1