3 final class AphrontFormRecaptchaControl
extends AphrontFormControl
{
5 protected function getCustomControlClass() {
6 return 'aphront-form-control-recaptcha';
9 protected function shouldRender() {
10 return self
::isRecaptchaEnabled();
13 public static function isRecaptchaEnabled() {
14 return PhabricatorEnv
::getEnvConfig('recaptcha.enabled');
17 public static function hasCaptchaResponse(AphrontRequest
$request) {
18 return $request->getBool('g-recaptcha-response');
21 public static function processCaptcha(AphrontRequest
$request) {
22 if (!self
::isRecaptchaEnabled()) {
26 $uri = 'https://www.google.com/recaptcha/api/siteverify';
28 'secret' => PhabricatorEnv
::getEnvConfig('recaptcha.private-key'),
29 'response' => $request->getStr('g-recaptcha-response'),
30 'remoteip' => $request->getRemoteAddress(),
33 list($body) = id(new HTTPSFuture($uri, $params))
37 $json = phutil_json_decode($body);
38 return (bool)idx($json, 'success');
41 protected function renderInput() {
42 $js = 'https://www.google.com/recaptcha/api.js';
43 $pubkey = PhabricatorEnv
::getEnvConfig('recaptcha.public-key');
45 CelerityAPI
::getStaticResourceResponse()
46 ->addContentSecurityPolicyURI('script-src', $js)
47 ->addContentSecurityPolicyURI('script-src', 'https://www.gstatic.com/')
48 ->addContentSecurityPolicyURI('frame-src', 'https://www.google.com/');
54 'class' => 'g-recaptcha',
55 'data-sitekey' => $pubkey,
60 'type' => 'text/javascript',