Skip to content
Snippets Groups Projects
Commit 2a73ccf2 authored by Sofiane Lasri's avatar Sofiane Lasri
Browse files

moved back to recaptcha 2

parent 5ec31d05
No related branches found
No related tags found
No related merge requests found
......@@ -15,18 +15,16 @@ if(isset($_GET["checkUsernameEmail"]) && !empty($_GET["checkUsernameEmail"])){
$return = null;
if(!empty($_POST)){
// On va s'assurer qu'il ne s'agisse pas d'un bot
if(isset($_POST['recaptcha_response'])){
if(isset($_POST['g-recaptcha-response'])){
// Build POST request:
$recaptcha_url = 'https://www.google.com/recaptcha/api/siteverify';
$recaptcha_secret = '6LfuDOYdAAAAABZDsplfnL8C5xGaE1-5MyyobuEF';
$recaptcha_response = $_POST['recaptcha_response'];
$recaptcha_response = $_POST['g-recaptcha-response'];
// Make and decode POST request:
$recaptcha = file_get_contents($recaptcha_url . '?secret=' . $recaptcha_secret . '&response=' . $recaptcha_response);
$recaptcha = json_decode($recaptcha);
if($recaptcha->success==1){
// Take action based on the score returned:
if ($recaptcha->score >= 0.5){
// On va regarder de quel type de formulaire il s'agit
if (isset($_POST['registerUsername'])) {
// Il s'agit d'une inscription
......@@ -160,10 +158,6 @@ if(isset($_GET["checkUsernameEmail"]) && !empty($_GET["checkUsernameEmail"])){
}else{
$return["error"] = 'Type de formulaire inconnu';
}
}else{
$return["error"] = "Le reCAPTCHA t'as identifié comme un robot. Re-essaie plus-tard.";
}
}else{
$return["error"] = "Nous rencontrons un problème avec le reCAPTCHA:";
foreach($recaptcha->{'error-codes'} as $return["error"]){
......
......@@ -17,15 +17,7 @@
<link rel="stylesheet" href="pages/assets/css/connexion.css">
<!-- Recaptcha -->
<script src="https://www.google.com/recaptcha/api.js?render=6LfuDOYdAAAAAEf8Ii1uzBXHVoUfeI2CK38US1-N"></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('6LfuDOYdAAAAAEf8Ii1uzBXHVoUfeI2CK38US1-N', { action: 'contact' }).then(function (token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
});
</script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
</head>
<body>
<div class="container h-100">
......@@ -61,8 +53,9 @@
</div>
</div>
<div class="g-recaptcha" data-sitekey="6Ld3jukdAAAAAFLO9t2Uyc3c9bru4kTcwffcG3mE"></div>
<br/>
<button type="button" name="submit" id="loginBtn" class="btn btn-orange">Se connecter</button>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
<a href="/register" class="text-orange">Pas encore inscrit? 😢</a>
</form>
</div>
......
......@@ -15,10 +15,10 @@
<meta content="#ed8930" data-react-helmet="true" name="theme-color" />
<!-- Recaptcha -->
<script src="https://www.google.com/recaptcha/api.js?render=6LfuDOYdAAAAAEf8Ii1uzBXHVoUfeI2CK38US1-N"></script>
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<script>
grecaptcha.ready(function () {
grecaptcha.execute('6LfuDOYdAAAAAEf8Ii1uzBXHVoUfeI2CK38US1-N', { action: 'contact' }).then(function (token) {
grecaptcha.execute('6Ld3jukdAAAAAFLO9t2Uyc3c9bru4kTcwffcG3mE', { action: 'contact' }).then(function (token) {
var recaptchaResponse = document.getElementById('recaptchaResponse');
recaptchaResponse.value = token;
});
......@@ -92,8 +92,9 @@
</div>
</div>
<div class="g-recaptcha" data-sitekey="6Ld3jukdAAAAAFLO9t2Uyc3c9bru4kTcwffcG3mE"></div>
<br/>
<button type="button" id="registerBtn" class="btn btn-orange">S'inscrire</button>
<input type="hidden" name="recaptcha_response" id="recaptchaResponse">
<a href="/login" class="text-orange">Déjà inscrit? 🌈</a>
</form>
</div>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment