diff --git a/resources/views/welcome.blade.php b/resources/views/welcome.blade.php
index 8ef066e..32e8afd 100644
--- a/resources/views/welcome.blade.php
+++ b/resources/views/welcome.blade.php
@@ -1,9 +1,5 @@
@php
- $publicSourceCode = trim((string) request()->query('src', ''));
$signupUrl = 'admin/c/xxf/login';
- if (preg_match('/^[A-Za-z0-9_-]{2,64}$/', $publicSourceCode) === 1) {
- $signupUrl .= '?src='.rawurlencode($publicSourceCode);
- }
@endphp
@@ -1990,6 +1986,14 @@
}
}
+ @if ($publicSourceCode)
+
+ @endif
diff --git a/routes/web.php b/routes/web.php
index b0f151e..721e1ec 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -2,6 +2,7 @@
use App\Http\Controllers\Api\ApplicationFileController;
use App\Http\Controllers\ChannelEntryController;
+use App\Models\PublicSourceChannel;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Route;
@@ -17,7 +18,22 @@ use Illuminate\Support\Facades\Route;
*/
Route::get('/', function () {
- return view('welcome');
+ $sourceCode = trim((string) request()->query('src', ''));
+ $publicSourceCode = null;
+ if (preg_match('/^[A-Za-z0-9_-]{2,64}$/', $sourceCode) === 1) {
+ try {
+ $publicSourceCode = PublicSourceChannel::query()
+ ->where('source_code', $sourceCode)
+ ->where('status', PublicSourceChannel::STATUS_ENABLED)
+ ->value('source_code');
+ } catch (Throwable) {
+ $publicSourceCode = null;
+ }
+ }
+
+ return view('welcome', [
+ 'publicSourceCode' => $publicSourceCode,
+ ]);
});
Route::get('/channel-entry', ChannelEntryController::class)->name('channel.entry');
diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/ExampleTest.php
index a731a94..e831079 100644
--- a/tests/Feature/ExampleTest.php
+++ b/tests/Feature/ExampleTest.php
@@ -2,7 +2,11 @@
namespace Tests\Feature;
+use App\Models\PublicSourceChannel;
// use Illuminate\Foundation\Testing\RefreshDatabase;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\DB;
+use Illuminate\Support\Facades\Schema;
use Tests\TestCase;
class ExampleTest extends TestCase
@@ -22,13 +26,48 @@ class ExampleTest extends TestCase
public function test_homepage_signup_link_preserves_public_source(): void
{
+ config([
+ 'database.default' => 'sqlite',
+ 'database.connections.sqlite' => [
+ 'driver' => 'sqlite',
+ 'database' => ':memory:',
+ 'prefix' => '',
+ 'foreign_key_constraints' => false,
+ ],
+ ]);
+ DB::purge();
+ DB::reconnect();
+ Schema::create('public_source_channels', function (Blueprint $table) {
+ $table->id();
+ $table->string('source_code', 64)->unique();
+ $table->string('source_name', 100);
+ $table->string('status')->default(PublicSourceChannel::STATUS_ENABLED);
+ $table->timestamps();
+ });
+ PublicSourceChannel::query()->create([
+ 'source_code' => 'poster_A',
+ 'source_name' => '海报 A',
+ 'status' => PublicSourceChannel::STATUS_ENABLED,
+ ]);
+ PublicSourceChannel::query()->create([
+ 'source_code' => 'closed_src',
+ 'source_name' => '停用渠道',
+ 'status' => PublicSourceChannel::STATUS_DISABLED,
+ ]);
+
$this->get('/?src=poster_A')
->assertOk()
- ->assertSee('href="admin/c/xxf/login?src=poster_A"', false);
+ ->assertSee('href="admin/c/xxf/login"', false)
+ ->assertSee("localStorage.setItem('cxxfds_public_source_code'", false)
+ ->assertSee('poster_A');
$this->get('/?src=bad%20code')
->assertOk()
->assertSee('href="admin/c/xxf/login"', false)
- ->assertDontSee('href="admin/c/xxf/login?src=', false);
+ ->assertDontSee("localStorage.setItem('cxxfds_public_source_code'", false);
+
+ $this->get('/?src=closed_src')
+ ->assertOk()
+ ->assertDontSee("localStorage.setItem('cxxfds_public_source_code'", false);
}
}