diff --git a/app/Http/Controllers/HomeController.php b/app/Http/Controllers/HomeController.php deleted file mode 100644 index fc36e23..0000000 --- a/app/Http/Controllers/HomeController.php +++ /dev/null @@ -1,14 +0,0 @@ -resetPage(); @@ -19,7 +23,14 @@ class ApplicationList extends Component public function approveApplication($uuid) { - Application::where('uuid', $uuid)->update(['status' => 1]); + $service = new SynapseService(); + $token = $service->createRegistrationToken(); + if (!$token) { + $this->error = true; + return; + } + + Application::where('uuid', $uuid)->update(['status' => 1, 'registration_token' => $token]); } public function rejectApplication($uuid) diff --git a/app/Models/Application.php b/app/Models/Application.php index e90730a..ba28c41 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -14,6 +14,7 @@ class Application extends Model protected $fillable = [ 'uuid', 'message', + 'registration_token', ]; public function uploads() diff --git a/app/Services/SynapseService.php b/app/Services/SynapseService.php new file mode 100644 index 0000000..0dde34b --- /dev/null +++ b/app/Services/SynapseService.php @@ -0,0 +1,35 @@ + "Bearer $token", + 'Content-Type' => 'application/json' + ])->post($endpoint . '/_synapse/admin/v1/registration_tokens/new', [ + 'uses_allowed' => 1, + 'length' => 12, + 'expiry_time' => now()->addWeek()->valueOf(), + ]); + + if ($response->successful()) { + return $response->json()['token'] ?? null; + } + + Log::error('Failed to create Synapse registration token', [ + 'status' => $response->status(), + 'body' => $response->body() + ]); + + return null; + } +} diff --git a/config/synapse.php b/config/synapse.php new file mode 100644 index 0000000..fd4ba6b --- /dev/null +++ b/config/synapse.php @@ -0,0 +1,27 @@ + env('SYNAPSE_ADMIN_API_TOKEN'), + + /* + |-------------------------------------------------------------------------- + | Admin API Endpoint + |-------------------------------------------------------------------------- + | + | This variable contains the admin endpoint for synapse. + | + */ + + 'admin_api_url' => env('SYNAPSE_ADMIN_API_URL'), + +]; diff --git a/database/migrations/2025_05_01_141403_create_applications_table.php b/database/migrations/2025_05_01_141403_create_applications_table.php index f2f9aec..d76217d 100644 --- a/database/migrations/2025_05_01_141403_create_applications_table.php +++ b/database/migrations/2025_05_01_141403_create_applications_table.php @@ -16,6 +16,7 @@ return new class extends Migration $table->uuid('uuid'); $table->tinyInteger('status')->default(0); $table->string('message'); + $table->string('registration_token')->nullable(); $table->timestamps(); }); } diff --git a/resources/views/livewire/application-status.blade.php b/resources/views/livewire/application-status.blade.php index 367064f..e2574be 100644 --- a/resources/views/livewire/application-status.blade.php +++ b/resources/views/livewire/application-status.blade.php @@ -8,7 +8,7 @@
- Created: - {{ Carbon\Carbon::parse($application->created_at)->diffForHumans(['parts' => 2]) }} -
+ @if ($application->registration_token) ++ Registration Token (valid until + {{ $application->updated_at->addWeek()->format('Y-m-d') }}) +
+