This commit is contained in:
JoseluCross
2018-10-26 16:42:47 +02:00
parent ed6f78e95a
commit 1ef6ae4b7a
4 changed files with 31 additions and 13 deletions

View File

@@ -79,6 +79,10 @@
<input type="checkbox" required="required" name="tos" id="tos"> <input type="checkbox" required="required" name="tos" id="tos">
</div> </div>
</div> </div>
<div class="form-group">
<label class="control-label col-sm-2" for="captcha"></label>
<div class="col-sm-10 g-recaptcha" data-sitekey="6Ld-C3cUAAAAADjyFgwdcVuLJqfCr0F3s2p1mE86"></div>
</div>
<div class="form-group"> <div class="form-group">
<div class="col-sm-offset-2 col-sm-10"> <div class="col-sm-offset-2 col-sm-10">
<button type="submit" class="btn btn-success">Submit</button> <button type="submit" class="btn btn-success">Submit</button>

2
Source/composer.lock generated
View File

@@ -1,7 +1,7 @@
{ {
"_readme": [ "_readme": [
"This file locks the dependencies of your project to a known state", "This file locks the dependencies of your project to a known state",
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "1d57e016803e2095db2110462e070da3", "content-hash": "1d57e016803e2095db2110462e070da3",

View File

@@ -19,7 +19,7 @@ $app = new Silex\Application();
use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response; use Symfony\Component\HttpFoundation\Response;
$app['debug'] = false; $app['debug'] = true;
$app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->register(new Silex\Provider\UrlGeneratorServiceProvider());
$app->register(new Silex\Provider\TwigServiceProvider(), array( $app->register(new Silex\Provider\TwigServiceProvider(), array(
'twig.path' => __DIR__.'/../', 'twig.path' => __DIR__.'/../',
@@ -143,7 +143,12 @@ $app->get('/login', function(Request $request) use ($app){
} }
else{ else{
$state = checkInfo($request); $state = checkInfo($request);
$captcha = checkCaptcha($request->get("g-recaptcha-response"));
if($captcha)
return loginOrRegister($state,$request); return loginOrRegister($state,$request);
else{
return "CAPTCHA_FAIL";
}
} }
})->bind('login')->method('GET|POST'); })->bind('login')->method('GET|POST');
@@ -159,7 +164,12 @@ $app->get('/signup', function(Request $request) use ($app){
return loginRegister('sign-up'); return loginRegister('sign-up');
}else{ }else{
$state = checkInfo($request); $state = checkInfo($request);
$captcha = checkCaptcha($request->get("g-recaptcha-response"));
if($captcha)
return loginOrRegister($state,$request); return loginOrRegister($state,$request);
else{
return "CAPTCHA_FAIL";
}
} }
})->bind('register')->method('GET|POST'); })->bind('register')->method('GET|POST');

View File

@@ -81,15 +81,19 @@ function groupByCategory($supported){
function checkCaptcha($response){ function checkCaptcha($response){
$url = "https://www.google.com/recaptcha/api/siteverify"; $url = "https://www.google.com/recaptcha/api/siteverify";
$post = 'secret='.'6Lc7gXAUAAAAAOTbo2u3IXoSB6KlhtVmUHTzpcGY&response='. $response; //$post = 'secret='.'6Ld-C3cUAAAAAC6NhPw-rn4LsdM2PjKg255H6j0o&response='. $response;
$post = array('secret' => "6Ld-C3cUAAAAAC6NhPw-rn4LsdM2PjKg255H6j0o",
'response' => $response);
$ch = curl_init( $url ); $options = array(
curl_setopt( $ch, CURLOPT_POST, 1); 'http' => array(
curl_setopt( $ch, CURLOPT_POSTFIELDS, $post); "header" => "Content-type: application/x-www-form-urlencoded\r\n",
curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); "method" => 'POST',
curl_setopt( $ch, CURLOPT_HEADER, 0); 'content'=> http_build_query($post)
curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); )
);
$context = stream_context_create($options);
$response = file_get_contents($url,false,$context);
$response = curl_exec( $ch ); return json_decode($response,true)["success"];
return json_decode($response)["success"];
} }