Skip to content

Commit

Permalink
Merge pull request #224 from pinkary-project/feat/age-rating-must-ref…
Browse files Browse the repository at this point in the history
…lect-18+

feat/age-rating-must-reflect-18+
  • Loading branch information
nunomaduro authored Apr 22, 2024
2 parents 85c6a44 + f5339c5 commit 899350c
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
1 change: 1 addition & 0 deletions app/Http/Controllers/Auth/RegisteredUserController.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ public function store(Request $request): RedirectResponse
'username' => ['required', 'string', 'min:4', 'max:50', 'unique:'.User::class, new Username],
'email' => ['required', 'string', 'lowercase', 'email', 'max:255', 'unique:'.User::class],
'password' => ['required', 'confirmed', Rules\Password::defaults()],
'terms' => ['required', 'accepted'],
'g-recaptcha-response' => app()->environment('production') ? ['required', new Recaptcha($request->ip())] : [],
]);

Expand Down
12 changes: 12 additions & 0 deletions resources/views/auth/register.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,18 @@ class="mt-2"
/>
</div>

<div class="mt-4">
<div class="flex items-center">
<input id="terms" name="terms" type="checkbox" class="h-4 w-4 mr-2 rounded border-gray-300 text-pink-600 focus:ring-pink-600" />

<x-input-label for="terms">
I am over 18 and I agree to the <a target="_blank" href="{{ route('terms') }}" class="text-pink-500 underline hover:no-underline">Terms of Service</a> and <a href="{{ route('privacy') }}" class="text-pink-500 underline hover:no-underline">Privacy Policy</a>.
</x-input-label>
</div>

<x-input-error :messages="$errors->get('terms')" class="mt-2" />
</div>

<div
class="g-recaptcha mt-4"
data-sitekey="{{ config('services.recaptcha.key') }}"
Expand Down
19 changes: 18 additions & 1 deletion tests/Http/Register/CreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
'email' => 'test@example.com',
'password' => 'm@9v_.*.XCN',
'password_confirmation' => 'm@9v_.*.XCN',
'terms' => true,
'g-recaptcha-response' => 'valid',
]);

Expand Down Expand Up @@ -52,7 +53,7 @@
->assertSessionHasErrors([
$field => 'The '.$field.' field is required.',
]);
})->with(['name', 'username', 'email', 'password']);
})->with(['name', 'username', 'email', 'password', 'terms']);

test('email must be valid', function () {
$response = $this->from('/register')->post('/register', [
Expand Down Expand Up @@ -80,6 +81,20 @@
->assertSessionHasErrors(['password' => 'The password field confirmation does not match.']);
});

test('users must be at least 18 years old', function () {
$response = $this->from('/register')->post('/register', [
'name' => 'Test User',
'username' => 'testuser',
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'not-password',
'terms' => false,
]);

$response->assertRedirect('/register')
->assertSessionHasErrors(['terms' => 'The terms field must be accepted.']);
});

test('username must be unique', function () {
User::factory()->create([
'username' => 'testuser',
Expand Down Expand Up @@ -255,6 +270,7 @@
'email' => 'test@laravel.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => true,
]);

$user = User::where('email', 'test@laravel.com')->first();
Expand All @@ -273,6 +289,7 @@
'email' => 'test@example.com',
'password' => 'password',
'password_confirmation' => 'password',
'terms' => true,
]);

expect(User::first()->prefers_anonymous_questions)->toBeTrue();
Expand Down

0 comments on commit 899350c

Please sign in to comment.