From: Dan Brown Date: Mon, 9 Sep 2019 20:19:08 +0000 (+0100) Subject: Added crude example of captcha usage X-Git-Url: http://source.bookstackapp.com/bookstack/commitdiff_plain/c49454da2833eb31b426e6b6ecfd790fad58567b Added crude example of captcha usage --- diff --git a/app/Http/Controllers/Auth/RegisterController.php b/app/Http/Controllers/Auth/RegisterController.php index c411f2363..cbb014bc3 100644 --- a/app/Http/Controllers/Auth/RegisterController.php +++ b/app/Http/Controllers/Auth/RegisterController.php @@ -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); } diff --git a/resources/views/auth/register.blade.php b/resources/views/auth/register.blade.php index 60ceba93c..47425196e 100644 --- a/resources/views/auth/register.blade.php +++ b/resources/views/auth/register.blade.php @@ -26,6 +26,14 @@ @include('form.password', ['name' => 'password', 'placeholder' => trans('auth.password_hint')]) +
+ +
+ @if($errors->has('g-recaptcha-response')) +
{{ $errors->first('g-recaptcha-response') }}
+ @endif +
+