diff --git a/app/Http/Controllers/Member/LibraryController.php b/app/Http/Controllers/Member/LibraryController.php index 7bca234..9ce3664 100644 --- a/app/Http/Controllers/Member/LibraryController.php +++ b/app/Http/Controllers/Member/LibraryController.php @@ -9,9 +9,9 @@ use App\Domain\Entitlement\Grant; use App\Domain\Entitlement\GrantStatus; use App\Http\Controllers\Controller; +use App\Http\SignedLink; use Illuminate\Http\Request; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\URL; use Illuminate\View\View; use Symfony\Component\HttpFoundation\StreamedResponse; @@ -56,7 +56,7 @@ public function show(Request $request, LicenseArticle $article): View 'allowed' => $decision->allowed, 'reason' => $decision->reason, 'url' => $decision->allowed - ? URL::temporarySignedRoute('member.media', now()->addMinutes(10), [ + ? SignedLink::temporary('member.media', now()->addMinutes(10), [ 'article' => $article->id, 'release' => $release->id, 'version' => $version->id, diff --git a/app/Http/SignedLink.php b/app/Http/SignedLink.php new file mode 100644 index 0000000..f987bb3 --- /dev/null +++ b/app/Http/SignedLink.php @@ -0,0 +1,20 @@ + $parameters + */ + public static function temporary(string $name, DateTimeInterface $expiration, array $parameters): string + { + return url(URL::temporarySignedRoute($name, $expiration, $parameters, false)); + } +} diff --git a/app/Models/User.php b/app/Models/User.php index 7d56856..354e374 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -6,6 +6,7 @@ use App\Domain\Identity\Party; use App\Domain\Identity\StaffRole; use App\Domain\Identity\StaffRoleAssignment; +use App\Notifications\VerifyEmailAddress; use Database\Factories\UserFactory; use Filament\Auth\MultiFactor\App\Concerns\InteractsWithAppAuthentication; use Filament\Auth\MultiFactor\App\Concerns\InteractsWithAppAuthenticationRecovery; @@ -42,6 +43,11 @@ protected function casts(): array ]; } + public function sendEmailVerificationNotification(): void + { + $this->notify(new VerifyEmailAddress); + } + public function party(): BelongsTo { return $this->belongsTo(Party::class); diff --git a/app/Notifications/VerifyEmailAddress.php b/app/Notifications/VerifyEmailAddress.php new file mode 100644 index 0000000..cf6d960 --- /dev/null +++ b/app/Notifications/VerifyEmailAddress.php @@ -0,0 +1,23 @@ +addMinutes((int) Config::get('auth.verification.expire', 60)), + [ + 'id' => $notifiable->getKey(), + 'hash' => sha1($notifiable->getEmailForVerification()), + ], + ); + } +} diff --git a/docker/nginx/default.conf b/docker/nginx/default.conf index 0bd9d22..5b7fc36 100644 --- a/docker/nginx/default.conf +++ b/docker/nginx/default.conf @@ -14,7 +14,11 @@ server { fastcgi_pass app:9000; fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name; include fastcgi_params; - fastcgi_param HTTP_X_FORWARDED_PROTO $http_x_forwarded_proto; + set $forwarded_proto $http_x_forwarded_proto; + if ($forwarded_proto = "") { + set $forwarded_proto $scheme; + } + fastcgi_param HTTP_X_FORWARDED_PROTO $forwarded_proto; fastcgi_param HTTP_X_FORWARDED_HOST $http_x_forwarded_host; fastcgi_param HTTP_X_FORWARDED_PORT $http_x_forwarded_port; fastcgi_param HTTP_X_FORWARDED_FOR $proxy_add_x_forwarded_for; diff --git a/routes/web.php b/routes/web.php index 3986a03..6aa0206 100644 --- a/routes/web.php +++ b/routes/web.php @@ -31,7 +31,7 @@ Route::middleware('auth')->group(function () { Route::get('/email/bestaetigen', [EmailVerificationController::class, 'notice'])->name('verification.notice'); Route::get('/email/bestaetigen/{id}/{hash}', [EmailVerificationController::class, 'verify']) - ->middleware('signed') + ->middleware('signed:relative') ->name('verification.verify'); Route::post('/email/erneut', [EmailVerificationController::class, 'send']) ->middleware('throttle:6,1') @@ -44,7 +44,7 @@ Route::get('/bibliothek', [LibraryController::class, 'index'])->name('library'); Route::get('/bibliothek/{article}', [LibraryController::class, 'show'])->name('article'); Route::get('/ausgabe/{article}/{release}/{version}/{action}', [LibraryController::class, 'media']) - ->middleware('signed') + ->middleware('signed:relative') ->name('media'); Route::get('/materialien', [LibraryController::class, 'materials'])->name('materials'); Route::get('/berechtigungen', [LibraryController::class, 'grants'])->name('grants'); diff --git a/tests/Feature/MembershipAccessTest.php b/tests/Feature/MembershipAccessTest.php index 877c65d..55ef7e5 100644 --- a/tests/Feature/MembershipAccessTest.php +++ b/tests/Feature/MembershipAccessTest.php @@ -13,13 +13,13 @@ use App\Domain\Entitlement\Grant; use App\Domain\Entitlement\GrantIssuer; use App\Domain\Entitlement\GrantStatus; +use App\Http\SignedLink; use App\Mail\OrderConfirmed; use App\Models\User; use Database\Seeders\DemoCatalogSeeder; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Mail; use Illuminate\Support\Facades\Storage; -use Illuminate\Support\Facades\URL; use Tests\TestCase; class MembershipAccessTest extends TestCase @@ -103,7 +103,7 @@ public function test_a_member_can_read_an_entitled_text_and_a_stranger_cannot(): $version = $release->contents->first()->elementVersion; $this->actingAs($member)->get(route('member.article', $article))->assertOk()->assertSee($article->code); - $url = URL::temporarySignedRoute('member.media', now()->addMinutes(5), [ + $url = SignedLink::temporary('member.media', now()->addMinutes(5), [ 'article' => $article->id, 'release' => $release->id, 'version' => $version->id, diff --git a/tests/Feature/RegistrationTest.php b/tests/Feature/RegistrationTest.php index d37199f..734b347 100644 --- a/tests/Feature/RegistrationTest.php +++ b/tests/Feature/RegistrationTest.php @@ -3,8 +3,8 @@ namespace Tests\Feature; use App\Models\User; +use App\Notifications\VerifyEmailAddress; use Illuminate\Auth\Notifications\ResetPassword; -use Illuminate\Auth\Notifications\VerifyEmail; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Support\Facades\Notification; use Tests\TestCase; @@ -47,7 +47,7 @@ public function test_registration_creates_a_person_and_sends_verification(): voi $this->assertSame('person', $user->party->type->value); $this->assertSame('private', $user->party->profile->visibility['display_name']); $this->assertAuthenticatedAs($user); - Notification::assertSentTo($user, VerifyEmail::class); + Notification::assertSentTo($user, VerifyEmailAddress::class); } public function test_placeholder_app_url_uses_the_address_opened_in_the_browser(): void @@ -66,8 +66,14 @@ public function test_placeholder_app_url_uses_the_address_opened_in_the_browser( $response->assertRedirect(url('/email/bestaetigen')); $user = User::query()->where('email', 'probe@example.test')->firstOrFail(); - Notification::assertSentTo($user, VerifyEmail::class, function (VerifyEmail $notification) use ($user): bool { + Notification::assertSentTo($user, VerifyEmailAddress::class, function (VerifyEmailAddress $notification) use ($user): bool { $link = $notification->toMail($user)->actionUrl; + $path = parse_url($link, PHP_URL_PATH); + $query = parse_url($link, PHP_URL_QUERY); + + $this->actingAs($user) + ->get($path.'?'.$query) + ->assertRedirect(route('member.dashboard')); return str_starts_with($link, url('/email/bestaetigen/')) && ! str_contains($link, 'CHANGE-ME.example');