Bravo List

Bravo List (http://www.bvlist.com/index.php)
-   Template Shares (http://www.bvlist.com/forumdisplay.php?f=26)
-   -   reCAPTCHA for tsue 2.2 (http://www.bvlist.com/showthread.php?t=11654)

joeroberts 5th August 2018 17:15

Quote:

Originally Posted by outtyrox (Post 52332)
Code:


class TSUE_captcha
{
    public function verifyCaptcha($recaptcha_challenge_field = "", $recaptcha_response_field = "")
    {
                //
                //PUT YOUR PRIVATE KEY HERE//
                $secret = "6LcsM2gUAAAAAAjbvuAs-YtADTLyAKkG96AX8nmK";
                //
                //
                //
                $remoteip = $_SERVER["REMOTE_ADDR"];
                $url = "https://www.google.com/recaptcha/api/siteverify";
                $response = $_POST["g-recaptcha-response"];
       
                // Curl Request
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_URL, $url);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, array(
                    'secret' => $secret,
                    'response' => $response,
                    'remoteip' => $remoteip
                    ));
                $curlData = curl_exec($curl);
                curl_close($curl);
       
                // Parse data
                $jsonResponse = json_decode($curlData);
                if ($jsonResponse->success === true)
                    return true;
                else
                    return false;
    }

}


problem here is
Code:

$response = $_POST["g-recaptcha-response"];
becuase you well not get that $_POST
you well need to use the
Code:

$recaptcha_response_field

outtyrox 5th August 2018 19:22

Quote:

Originally Posted by joeroberts (Post 52353)
problem here is
Code:

$response = $_POST["g-recaptcha-response"];
becuase you well not get that $_POST
you well need to use the
Code:

$recaptcha_response_field

correct because not part the form so the js has to do it from my understanding which it does but somewhere there's still an issue I cannot resolve.

I've added the following to debug it but I'm not understanding the issue yet.

//echo "
";
//print_r($_POST);

and

//testing to see if response working. comment out once working
echo "
";
print_r($response);



I thought I just use the $recaptcha_response_field for the response varible but even that doesn't produce a success for the response


here's what i see from the class_captcha.php response



//echo "
";
//print_r($_POST);
https://s22.postimg.cc/wo0r7fmpd/Scr...1.09.36_PM.png



CAPTCHA success failing
https://s22.postimg.cc/3lmh4xddt/Scr...1.12.29_PM.png


//testing to see if response working. comment out once working
echo "
";
print_r($response);
https://s22.postimg.cc/7ur7756dd/Scr...1.12.56_PM.png

Bump: I have fixed this and here's how.

the _POST of the variables to the response was not being assigned for some reason when calling ajax/signup.php at sigup and running the library/class_captcha.php

I simply made a variable in ajax/signup.php to assign the response to and that got ride the response not assigned error


edited working class_captcha.php

Code:


class TSUE_captcha
{
    public function verifyCaptcha($recaptcha_challenge_field, $recaptcha_response_field)
    {
               
                //
                //PUT YOUR PRIVATE KEY HERE//
                $secret = "6LcsM2gUAAAAAAjbvuAs-YtADTLyAKkG96AX8nmK";
                //
                //
                //
                global $_POST;
                $remoteip = $_SERVER["REMOTE_ADDR"];
                $url = "https://www.google.com/recaptcha/api/siteverify";
       
                // Curl Request
                $curl = curl_init();
                curl_setopt($curl, CURLOPT_URL, $url);
                curl_setopt($curl, CURLOPT_POST, true);
                curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
                curl_setopt($curl, CURLOPT_POSTFIELDS, array(
                    'secret' => $secret,
                    'response' => $recaptcha_response_field,
                    'remoteip' => $remoteip
                    ));
                $result = curl_exec($curl);
                curl_close($curl);
       
                $result = json_decode($result);
               
               
                //echo "
";
                //echo print_r($recaptcha_response_field);
                //echo print_r($result);
                //echo "
";
               
               
                if ($result -> success) {
                    return true;
                }
                else
                {
                    return false;
                }
    }

}
?>



edited ajax/signup.php


- search for $_POST["g-recaptcha-response"]; in ajax/signup.php
- created a variable $recaptcha_response_field = $_POST["g-recaptcha-response"];
- edit if( !$verifyCaptcha->verifyCaptcha($recaptcha_challenge_field, $_POST["g-recaptcha-response"];))

and make it

- if( !$verifyCaptcha->verifyCaptcha($recaptcha_challenge_field, $recaptcha_response_field))


https://s22.postimg.cc/ysqoipi75/Scr...1.37.47_AM.png

Bump: Here's the updated TSUE v2.2 source code with Recaptcha v2 working

- Complete with files updated included that joe made with one minor edit to /ajax/signup.php
- Updated default database with template edits already done so you dont have to do them. only the public key entry in captcha template

1. Extract and upload directory to your domain web host
2. Create a database in CPANEL
3. Use MyPHPAdmin and Import default database file to your newly created database
4. Run installer: https://yourdomainnamehere.com/tsue_install/install.php

5. Make a Google Recaptcha key pair for your domain

- Edit template named captcha and put in your and public captcha key
- Edit /library/classes/class_captcha.php and put in your private captcha key

6. Proceed as normal

Credits to joe roberts for file updates and Napon for his work.


Code:

https://my.pcloud.com/publink/show?code=XZVvdW7ZO707LfnGq6L3cvv6lbVjN7gc9Sak
Bump: ========================================
use this to resize the captcha.

note: this is the catpcha part edited in the template. don't forget to enter your site key of course.


Code:




All times are GMT +2. The time now is 13:52.

Powered by vBulletin® Version 3.8.11 Beta 3
Copyright ©2000 - 2024, vBulletin Solutions Inc.