Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F91549692
AphrontFormRecaptchaControl.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Nov 12, 03:21
Size
1 KB
Mime Type
text/x-php
Expires
Thu, Nov 14, 03:21 (2 d)
Engine
blob
Format
Raw Data
Handle
22281928
Attached To
rPH Phabricator
AphrontFormRecaptchaControl.php
View Options
<?php
/**
*
* @phutil-external-symbol function recaptcha_get_html
* @phutil-external-symbol function recaptcha_check_answer
*/
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'
);
}
private
static
function
requireLib
()
{
$root
=
phutil_get_library_root
(
'phabricator'
);
require_once
dirname
(
$root
).
'/externals/recaptcha/recaptchalib.php'
;
}
public
static
function
hasCaptchaResponse
(
AphrontRequest
$request
)
{
return
$request
->
getBool
(
'recaptcha_response_field'
);
}
public
static
function
processCaptcha
(
AphrontRequest
$request
)
{
if
(!
self
::
isRecaptchaEnabled
())
{
return
true
;
}
self
::
requireLib
();
$challenge
=
$request
->
getStr
(
'recaptcha_challenge_field'
);
$response
=
$request
->
getStr
(
'recaptcha_response_field'
);
$resp
=
recaptcha_check_answer
(
PhabricatorEnv
::
getEnvConfig
(
'recaptcha.private-key'
),
$_SERVER
[
'REMOTE_ADDR'
],
$challenge
,
$response
);
return
(
bool
)@
$resp
->
is_valid
;
}
protected
function
renderInput
()
{
self
::
requireLib
();
$uri
=
new
PhutilURI
(
PhabricatorEnv
::
getEnvConfig
(
'phabricator.base-uri'
));
$protocol
=
$uri
->
getProtocol
();
$use_ssl
=
(
$protocol
==
'https'
);
return
phutil_safe_html
(
recaptcha_get_html
(
PhabricatorEnv
::
getEnvConfig
(
'recaptcha.public-key'
),
$error
=
null
,
$use_ssl
));
}
}
Event Timeline
Log In to Comment