]> BookStack Code Mirror - bookstack/commitdiff
Added crude example of captcha usage captcha_example
authorDan Brown <redacted>
Mon, 9 Sep 2019 20:19:08 +0000 (21:19 +0100)
committerDan Brown <redacted>
Mon, 9 Sep 2019 20:19:08 +0000 (21:19 +0100)
app/Http/Controllers/Auth/RegisterController.php
resources/views/auth/register.blade.php

index c411f2363210999c6b44e578a19024b734e85fba..cbb014bc3cb2dd8cf997ea533444a79db3af1e48 100644 (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);
     }
index 60ceba93c55b78cbc4feaee14a4e337cfed926f2..47425196e15c0cb4725dab97bf659c39639fe5b8 100644 (file)
                     @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>