Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace App\Models;

// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
Expand All @@ -14,7 +14,7 @@
use Laravel\Jetstream\HasTeams;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
class User extends Authenticatable implements MustVerifyEmail
{
use HasApiTokens;

Expand Down
2 changes: 1 addition & 1 deletion config/fortify.php
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@
'features' => [
Features::registration(),
Features::resetPasswords(),
// Features::emailVerification(),
Features::emailVerification(),
Features::updateProfileInformation(),
Features::updatePasswords(),
Features::twoFactorAuthentication([
Expand Down
6 changes: 5 additions & 1 deletion database/factories/EventFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use App\Models\Event;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;

/**
* @extends Factory<Event>
Expand Down Expand Up @@ -54,7 +55,10 @@ public function definition(): array
$event = $this->faker->randomElement($eventTypes);

return [
'name' => $event['name'],
// Append a random suffix so repeated factory calls for the same
// user can't collide against the (user_id, name) unique
// constraint (see #100).
'name' => $event['name'].'_'.Str::random(6),
'description' => $event['description'],
];
}
Expand Down
5 changes: 3 additions & 2 deletions database/seeders/WebhookSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use App\Models\Event;
use App\Models\User;
use Illuminate\Database\Seeder;
use Illuminate\Support\Str;

class WebhookSeeder extends Seeder
{
Expand Down Expand Up @@ -98,7 +99,7 @@ public function run(): void
$event = Event::factory()
->for($user)
->create([
'name' => $eventType.'_'.time().'_'.rand(1000, 9999),
'name' => $eventType.'_'.Str::ulid(),
'event_type' => $eventType,
'description' => 'Triggered when '.str_replace('.', ' ', $eventType).' occurs',
]);
Expand Down Expand Up @@ -141,7 +142,7 @@ public function run(): void
$event = Event::factory()
->for($user)
->create([
'name' => $eventType.'_recent_'.time().'_'.rand(1000, 9999),
'name' => $eventType.'_recent_'.Str::ulid(),
'event_type' => $eventType,
'description' => 'Recent '.str_replace('.', ' ', $eventType).' event',
'created_at' => $createdAt,
Expand Down
30 changes: 30 additions & 0 deletions tests/Feature/EmailVerificationEnforcementTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace Tests\Feature;

use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;

class EmailVerificationEnforcementTest extends TestCase
{
use RefreshDatabase;

public function test_unverified_user_is_redirected_away_from_the_dashboard(): void
{
$user = User::factory()->unverified()->create();

$response = $this->actingAs($user)->get('/dashboard');

$response->assertRedirect(route('verification.notice'));
}

public function test_verified_user_can_access_the_dashboard(): void
{
$user = User::factory()->create();

$response = $this->actingAs($user)->get('/dashboard');

$response->assertOk();
}
}
Loading