Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat/age-rating-must-reflect-18+ #224

Merged
merged 3 commits into from
Apr 22, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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()],
'is-over-18' => ['required', 'accepted'],
nunomaduro marked this conversation as resolved.
Show resolved Hide resolved
'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 @@ -56,6 +56,18 @@ class="mt-1 block w-full"
<x-input-error :messages="$errors->get('password_confirmation')" class="mt-2" />
</div>

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

<x-input-label for="is-over-18">
I certify that I am at least 18 years old and that I agree to the <a href="{{ route('terms') }}" class="text-pink-500 underline hover:no-underline">Terms and Policies</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('is-over-18')" class="mt-2" />
</div>

<div class="g-recaptcha mt-4" data-sitekey="{{ config('services.recaptcha.key') }}" data-theme="dark"></div>

@if ($errors->has('g-recaptcha-response'))
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',
'is-over-18' => 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', 'is-over-18']);

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',
'is-over-18' => false,
]);

$response->assertRedirect('/register')
->assertSessionHasErrors(['is-over-18' => 'The is-over-18 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',
'is-over-18' => true,
]);

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

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