Added crude example of captcha usage

This commit is contained in:
Dan Brown 2019-09-09 21:19:08 +01:00
parent 23db81f2cc
commit c49454da28
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
2 changed files with 23 additions and 0 deletions

View File

@ -13,6 +13,7 @@ use BookStack\Exceptions\SocialSignInException;
use BookStack\Exceptions\UserRegistrationException;
use BookStack\Http\Controllers\Controller;
use Exception;
use GuzzleHttp\Client;
use Illuminate\Foundation\Auth\RegistersUsers;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
@ -115,6 +116,20 @@ class RegisterController extends Controller
$this->checkRegistrationAllowed();
$this->validator($request->all())->validate();
$captcha = $request->get('g-recaptcha-response');
$resp = (new Client())->post('https://www.google.com/recaptcha/api/siteverify', [
'form_params' => [
'response' => $captcha,
'secret' => '%%secret_key%%',
]
]);
$respBody = json_decode($resp->getBody());
if (!$respBody->success) {
return redirect()->back()->withInput()->withErrors([
'g-recaptcha-response' => 'Did not pass captcha',
]);
}
$userData = $request->all();
return $this->registerUser($userData);
}

View File

@ -26,6 +26,14 @@
@include('form.password', ['name' => 'password', 'placeholder' => trans('auth.password_hint')])
</div>
<div class="form-group">
<script src="https://www.google.com/recaptcha/api.js" async defer></script>
<div class="g-recaptcha" data-sitekey="%%site_key%%"></div>
@if($errors->has('g-recaptcha-response'))
<div class="text-neg text-small">{{ $errors->first('g-recaptcha-response') }}</div>
@endif
</div>
<div class="grid half collapse-xs gap-xl v-center mt-m">
<div class="text-small">
<a href="{{ url('/login') }}">{{ trans('auth.already_have_account') }}</a>