-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
81ce098
commit d3a8cac
Showing
4 changed files
with
185 additions
and
11 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<? | ||
include("dao.php"); | ||
|
||
header('Content-Type: application/json'); | ||
|
||
if(!isset($_POST['robot_identifier'])) | ||
exit(json_encode(array('success' => false, 'message' => "Missing robot identifier!"))); | ||
if(!isset($_POST['g-recaptcha-response'])) | ||
exit(json_encode(array('success' => false, 'message' => "Missing g recaptcha response!"))); | ||
|
||
$id = $_POST['robot_identifier']; | ||
$captcha = $_POST['g-recaptcha-response']; | ||
$ip = $_SERVER['REMOTE_ADDR']; | ||
|
||
if(!isValid($captcha, $ip)) | ||
exit(json_encode(array('success' => false, 'message' => "reCaptcha was not valid!"))); | ||
|
||
$dao = new dao(); | ||
$result = $dao->getRecaptchaListing($id); | ||
$dao->deleteRecaptchaListing($id); | ||
|
||
if(!$result['found']) | ||
exit(json_encode(array('success' => false, 'message' => "Generation data not found on server!"))); | ||
|
||
exit(json_encode(array('success' => true, 'result' => array('access' => $result['access'], 'refresh' => $result['refresh'])))); | ||
|
||
function isValid($captcha, $ip) { | ||
try { | ||
|
||
$url = 'https://www.google.com/recaptcha/api/siteverify'; | ||
$data = ['secret' => RECAPTCHA_SECRET, | ||
'response' => $captcha, | ||
'remoteip' => $ip]; | ||
|
||
$options = [ | ||
'http' => [ | ||
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | ||
'method' => 'POST', | ||
'content' => http_build_query($data) | ||
] | ||
]; | ||
|
||
$context = stream_context_create($options); | ||
$result = file_get_contents($url, false, $context); | ||
return json_decode($result)->success; | ||
} | ||
catch (Exception $e) { | ||
return null; | ||
} | ||
} | ||
|
||
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters