[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/view/form/control/ -> AphrontFormRecaptchaControl.php (source)

   1  <?php
   2  
   3  /**
   4   *
   5   * @phutil-external-symbol function recaptcha_get_html
   6   * @phutil-external-symbol function recaptcha_check_answer
   7   */
   8  final class AphrontFormRecaptchaControl extends AphrontFormControl {
   9  
  10    protected function getCustomControlClass() {
  11      return 'aphront-form-control-recaptcha';
  12    }
  13  
  14    protected function shouldRender() {
  15      return self::isRecaptchaEnabled();
  16    }
  17  
  18    public static function isRecaptchaEnabled() {
  19      return PhabricatorEnv::getEnvConfig('recaptcha.enabled');
  20    }
  21  
  22    private static function requireLib() {
  23      $root = phutil_get_library_root('phabricator');
  24      require_once dirname($root).'/externals/recaptcha/recaptchalib.php';
  25    }
  26  
  27    public static function hasCaptchaResponse(AphrontRequest $request) {
  28      return $request->getBool('recaptcha_response_field');
  29    }
  30  
  31    public static function processCaptcha(AphrontRequest $request) {
  32      if (!self::isRecaptchaEnabled()) {
  33        return true;
  34      }
  35  
  36      self::requireLib();
  37  
  38      $challenge = $request->getStr('recaptcha_challenge_field');
  39      $response = $request->getStr('recaptcha_response_field');
  40      $resp = recaptcha_check_answer(
  41        PhabricatorEnv::getEnvConfig('recaptcha.private-key'),
  42        $_SERVER['REMOTE_ADDR'],
  43        $challenge,
  44        $response);
  45  
  46      return (bool)@$resp->is_valid;
  47    }
  48  
  49    protected function renderInput() {
  50      self::requireLib();
  51  
  52      $uri = new PhutilURI(PhabricatorEnv::getEnvConfig('phabricator.base-uri'));
  53      $protocol = $uri->getProtocol();
  54      $use_ssl = ($protocol == 'https');
  55  
  56      return phutil_safe_html(recaptcha_get_html(
  57        PhabricatorEnv::getEnvConfig('recaptcha.public-key'),
  58        $error = null,
  59        $use_ssl));
  60    }
  61  
  62  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1