From 1ef6ae4b7ad1a35527149a8023bd34a8024adec6 Mon Sep 17 00:00:00 2001 From: JoseluCross Date: Fri, 26 Oct 2018 16:42:47 +0200 Subject: [PATCH] ReCaptcha #10 --- Source/assets/html/loginregister.twig | 4 ++++ Source/composer.lock | 2 +- Source/src/app.php | 16 +++++++++++++--- Source/src/functions.php | 22 +++++++++++++--------- 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/Source/assets/html/loginregister.twig b/Source/assets/html/loginregister.twig index 727252e..abfe661 100644 --- a/Source/assets/html/loginregister.twig +++ b/Source/assets/html/loginregister.twig @@ -79,6 +79,10 @@ +
+ +
+
diff --git a/Source/composer.lock b/Source/composer.lock index ee75759..cdbb067 100644 --- a/Source/composer.lock +++ b/Source/composer.lock @@ -1,7 +1,7 @@ { "_readme": [ "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" ], "content-hash": "1d57e016803e2095db2110462e070da3", diff --git a/Source/src/app.php b/Source/src/app.php index 931be6c..3038f81 100644 --- a/Source/src/app.php +++ b/Source/src/app.php @@ -19,7 +19,7 @@ $app = new Silex\Application(); use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -$app['debug'] = false; +$app['debug'] = true; $app->register(new Silex\Provider\UrlGeneratorServiceProvider()); $app->register(new Silex\Provider\TwigServiceProvider(), array( 'twig.path' => __DIR__.'/../', @@ -143,7 +143,12 @@ $app->get('/login', function(Request $request) use ($app){ } else{ $state = checkInfo($request); - return loginOrRegister($state,$request); + $captcha = checkCaptcha($request->get("g-recaptcha-response")); + if($captcha) + return loginOrRegister($state,$request); + else{ + return "CAPTCHA_FAIL"; + } } })->bind('login')->method('GET|POST'); @@ -159,7 +164,12 @@ $app->get('/signup', function(Request $request) use ($app){ return loginRegister('sign-up'); }else{ $state = checkInfo($request); - return loginOrRegister($state,$request); + $captcha = checkCaptcha($request->get("g-recaptcha-response")); + if($captcha) + return loginOrRegister($state,$request); + else{ + return "CAPTCHA_FAIL"; + } } })->bind('register')->method('GET|POST'); diff --git a/Source/src/functions.php b/Source/src/functions.php index 6037cb4..0022d99 100644 --- a/Source/src/functions.php +++ b/Source/src/functions.php @@ -81,15 +81,19 @@ function groupByCategory($supported){ function checkCaptcha($response){ $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 ); - curl_setopt( $ch, CURLOPT_POST, 1); - curl_setopt( $ch, CURLOPT_POSTFIELDS, $post); - curl_setopt( $ch, CURLOPT_FOLLOWLOCATION, 1); - curl_setopt( $ch, CURLOPT_HEADER, 0); - curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1); + $options = array( + 'http' => array( + "header" => "Content-type: application/x-www-form-urlencoded\r\n", + "method" => 'POST', + 'content'=> http_build_query($post) + ) + ); + $context = stream_context_create($options); + $response = file_get_contents($url,false,$context); - $response = curl_exec( $ch ); - return json_decode($response)["success"]; + return json_decode($response,true)["success"]; } \ No newline at end of file