Skip to content

Commit 5c28bcf

Browse files
committed
Registration: Reviewed added simple honeypot, added testing
Also cleaned up old RegistrationController syntax. Review of #4970
1 parent 0d2a268 commit 5c28bcf

File tree

3 files changed

+26
-16
lines changed

3 files changed

+26
-16
lines changed

app/Access/Controllers/RegisterController.php

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,13 @@
1515

1616
class RegisterController extends Controller
1717
{
18-
protected SocialDriverManager $socialDriverManager;
19-
protected RegistrationService $registrationService;
20-
protected LoginService $loginService;
21-
22-
/**
23-
* Create a new controller instance.
24-
*/
2518
public function __construct(
26-
SocialDriverManager $socialDriverManager,
27-
RegistrationService $registrationService,
28-
LoginService $loginService
19+
protected SocialDriverManager $socialDriverManager,
20+
protected RegistrationService $registrationService,
21+
protected LoginService $loginService
2922
) {
3023
$this->middleware('guest');
3124
$this->middleware('guard:standard');
32-
33-
$this->socialDriverManager = $socialDriverManager;
34-
$this->registrationService = $registrationService;
35-
$this->loginService = $loginService;
3625
}
3726

3827
/**
@@ -87,7 +76,8 @@ protected function validator(array $data): ValidatorContract
8776
'name' => ['required', 'min:2', 'max:100'],
8877
'email' => ['required', 'email', 'max:255', 'unique:users'],
8978
'password' => ['required', Password::default()],
90-
'username' => ['prohibited'], // this is a honeypot for bots that must not be filled in
79+
// Basic honey for bots that must not be filled in
80+
'username' => ['prohibited'],
9181
]);
9282
}
9383
}

resources/views/auth/register.blade.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@
1313
<form action="{{ url("/register") }}" method="POST" class="mt-l stretch-inputs">
1414
{!! csrf_field() !!}
1515

16+
{{-- Simple honeypot field --}}
1617
<div class="form-group ambrosia-container" aria-hidden="true">
17-
<label for="name">{{ trans('auth.name') }}</label>
18+
<label for="username">{{ trans('auth.name') }}</label>
1819
@include('form.text', ['name' => 'username'])
1920
</div>
2021

tests/Auth/RegistrationTest.php

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,4 +184,23 @@ public function test_registration_validation()
184184
$resp->assertSee('The email must be a valid email address.');
185185
$resp->assertSee('The password must be at least 8 characters.');
186186
}
187+
188+
public function test_registration_simple_honeypot_active()
189+
{
190+
$this->setSettings(['registration-enabled' => 'true']);
191+
192+
$resp = $this->get('/register');
193+
$this->withHtml($resp)->assertElementExists('form input[name="username"]');
194+
195+
$resp = $this->post('/register', [
196+
'name' => 'Barry',
197+
'email' => 'barrybot@example.com',
198+
'password' => 'barryIsTheBestBot',
199+
'username' => 'MyUsername'
200+
]);
201+
$resp->assertRedirect('/register');
202+
203+
$resp = $this->followRedirects($resp);
204+
$this->withHtml($resp)->assertElementExists('form input[name="username"].text-neg');
205+
}
187206
}

0 commit comments

Comments
 (0)