Skip to content

Commit 2bb3b24

Browse files
committed
Implement ReCaptcha on threads
1 parent 7482b27 commit 2bb3b24

File tree

3 files changed

+25
-1
lines changed

3 files changed

+25
-1
lines changed

app/controllers/AuthController.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ public function postSignupConfirm()
4848
}
4949

5050
/** @var \Illuminate\Validation\Validator $validator */
51-
$validator = Validator::make(Input::all(), ['g-recaptcha-response' => 'required|recaptcha']);
51+
$validator = Validator::make(Input::only('g-recaptcha-response'), [
52+
'g-recaptcha-response' => 'required|recaptcha'
53+
]);
5254

5355
if ($validator->fails()) {
5456
return Redirect::action('AuthController@getSignupConfirm')

app/controllers/Forum/ForumThreadsController.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,17 @@ public function postCreateThread()
9292
return Redirect::action('ForumThreadsController@getCreateThread');
9393
}
9494

95+
/** @var \Illuminate\Validation\Validator $validator */
96+
$validator = Validator::make(Input::only('g-recaptcha-response'), [
97+
'g-recaptcha-response' => 'required|recaptcha'
98+
]);
99+
100+
if ($validator->fails()) {
101+
return Redirect::action('ForumThreadsController@getCreateThread')
102+
->exceptInput('g-recaptcha-response')
103+
->withErrors($validator->errors());
104+
}
105+
95106
return $this->threadCreator->create($this, [
96107
'subject' => Input::get('subject'),
97108
'body' => Input::get('body'),

app/views/forum/threads/create.blade.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
<div class="header">
99
<h1>Create Thread</h1>
1010
</div>
11+
12+
{{ ReCaptcha::getScript() }}
13+
1114
{{ Form::open(['data-persist' => 'garlic', 'data-expires' => '600']) }}
1215

1316
<section class="padding">
@@ -72,6 +75,14 @@
7275
@include('forum._tag_chooser')
7376
</div>
7477

78+
<div class="form-row">
79+
<p>{{ ReCaptcha::getWidget() }}</p>
80+
81+
@if ($errors->has('g-recaptcha-response'))
82+
<p>Please fill in the captcha field correctly.</p>
83+
@endif
84+
</div>
85+
7586
<div class="form-row">
7687
{{ Form::button('Save', ['type' => 'submit', 'class' => 'button']) }}
7788
</div>

0 commit comments

Comments
 (0)