Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F972570
AphrontFormRecaptchaControl.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
1 KB
Referenced Files
None
Subscribers
None
AphrontFormRecaptchaControl.php
View Options
<?php
final
class
AphrontFormRecaptchaControl
extends
AphrontFormControl
{
protected
function
getCustomControlClass
()
{
return
'aphront-form-control-recaptcha'
;
}
protected
function
shouldRender
()
{
return
self
::
isRecaptchaEnabled
();
}
public
static
function
isRecaptchaEnabled
()
{
return
PhabricatorEnv
::
getEnvConfig
(
'recaptcha.enabled'
);
}
public
static
function
hasCaptchaResponse
(
AphrontRequest
$request
)
{
return
$request
->
getBool
(
'g-recaptcha-response'
);
}
public
static
function
processCaptcha
(
AphrontRequest
$request
)
{
if
(!
self
::
isRecaptchaEnabled
())
{
return
true
;
}
$uri
=
'https://www.google.com/recaptcha/api/siteverify'
;
$params
=
array
(
'secret'
=>
PhabricatorEnv
::
getEnvConfig
(
'recaptcha.private-key'
),
'response'
=>
$request
->
getStr
(
'g-recaptcha-response'
),
'remoteip'
=>
$request
->
getRemoteAddress
(),
);
list
(
$body
)
=
id
(
new
HTTPSFuture
(
$uri
,
$params
))
->
setMethod
(
'POST'
)
->
resolvex
();
$json
=
phutil_json_decode
(
$body
);
return
(
bool
)
idx
(
$json
,
'success'
);
}
protected
function
renderInput
()
{
$js
=
'https://www.google.com/recaptcha/api.js'
;
$pubkey
=
PhabricatorEnv
::
getEnvConfig
(
'recaptcha.public-key'
);
CelerityAPI
::
getStaticResourceResponse
()
->
addContentSecurityPolicyURI
(
'script-src'
,
$js
)
->
addContentSecurityPolicyURI
(
'script-src'
,
'https://www.gstatic.com/'
)
->
addContentSecurityPolicyURI
(
'frame-src'
,
'https://www.google.com/'
);
return
array
(
phutil_tag
(
'div'
,
array
(
'class'
=>
'g-recaptcha'
,
'data-sitekey'
=>
$pubkey
,
)),
phutil_tag
(
'script'
,
array
(
'type'
=>
'text/javascript'
,
'src'
=>
$js
,
)),
);
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Wed, Jun 18, 6:16 AM (1 d, 16 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
229163
Default Alt Text
AphrontFormRecaptchaControl.php (1 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment