feature/MAPG-242-add-captcha-for-signup-and-password-reset #54

Merged
bence merged 3 commits from feature/MAPG-242-add-captcha-for-signup-and-password-reset into develop 2022-05-26 18:47:47 +02:00
2 changed files with 19 additions and 0 deletions
Showing only changes of commit 241d2f2b30 - Show all commits

View File

@ -19,6 +19,7 @@ use MapGuesser\Repository\UserRepository;
use MapGuesser\Response\HtmlContent;
use MapGuesser\Response\JsonContent;
use MapGuesser\Response\Redirect;
use MapGuesser\Util\CaptchaValidator;
use MapGuesser\Util\JwtParser;
class LoginController
@ -285,6 +286,18 @@ class LoginController
return new JsonContent($data);
}
if (!empty($_ENV['RECAPTCHA_SITEKEY'])) {
if (!$this->request->post('g-recaptcha-response')) {
return new JsonContent(['error' => ['errorText' => 'Please check "I\'m not a robot" in the reCAPTCHA box!']]);
}
$captchaValidator = new CaptchaValidator();
$captchaResponse = $captchaValidator->validate($this->request->post('g-recaptcha-response'));
if (!$captchaResponse['success']) {
return new JsonContent(['error' => ['errorText' => 'reCAPTCHA challenge failed. Please try again!']]);
}
}
if (filter_var($this->request->post('email'), FILTER_VALIDATE_EMAIL) === false) {
return new JsonContent(['error' => ['errorText' => 'The given email address is not valid.']]);
}

View File

@ -1,3 +1,4 @@
@js(https://www.google.com/recaptcha/api.js)
@js(js/login/signup.js)
@extends(templates/layout_normal)
@ -15,6 +16,11 @@
<input type="password" class="text big fullWidth marginTop" name="password" placeholder="Password" required minlength="6">
<input type="password" class="text big fullWidth marginTop" name="password_confirm" placeholder="Password confirmation" minlength="6">
<?php endif; ?>
<?php if (!empty($_ENV['RECAPTCHA_SITEKEY'])): ?>
<div class="marginTop">
<div class="g-recaptcha" data-sitekey="<?= $_ENV['RECAPTCHA_SITEKEY'] ?>"></div>
</div>
<?php endif; ?>
<p id="signupFormError" class="formError justify marginTop"></p>
<div class="right">
<button class="marginTop" type="submit">Sign up</button><!--