Admin: Set synapse endpoint and access token through ui

This commit is contained in:
weeb 2025-05-03 12:10:35 +02:00
parent 2717babc4b
commit 437791b581
8 changed files with 113 additions and 29 deletions

View File

@ -0,0 +1,33 @@
<?php
namespace App\Livewire\Settings;
use App\Models\Settings;
use Livewire\Component;
class Synapse extends Component
{
public string $synapseEndpoint;
public string $synapseAccessToken;
/**
* Mount the component.
*/
public function mount(): void
{
$this->synapseEndpoint = Settings::get('synapse_endpoint', '');
$this->synapseAccessToken = Settings::get('synapse_access_token', '');
}
public function save(): void
{
Settings::set('synapse_endpoint', $this->synapseEndpoint);
Settings::set('synapse_access_token', $this->synapseAccessToken);
}
public function render()
{
return view('livewire.settings.synapse');
}
}

23
app/Models/Settings.php Normal file
View File

@ -0,0 +1,23 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Settings extends Model
{
protected $fillable = [
'key',
'value'
];
public static function get($key, $default = null)
{
return static::where('key', $key)->value('value') ?? $default;
}
public static function set($key, $value)
{
return static::updateOrCreate(['key' => $key], ['value' => $value]);
}
}

View File

@ -2,6 +2,8 @@
namespace App\Services;
use App\Models\Settings;
use Illuminate\Support\Facades\Http;
use Illuminate\Support\Facades\Log;
@ -9,8 +11,8 @@ class SynapseService
{
public function createRegistrationToken(): ?string
{
$token = config('synapse.admin_api_token');
$endpoint = config('synapse.admin_api_url');
$token = Settings::get('synapse_access_token', '');
$endpoint = Settings::get('synapse_endpoint', '');
$response = Http::withHeaders([
'Authorization' => "Bearer $token",

View File

@ -1,27 +0,0 @@
<?php
return [
/*
|--------------------------------------------------------------------------
| Admin API Token
|--------------------------------------------------------------------------
|
| This variable contains the authorization bearer for synapse.
|
*/
'admin_api_token' => env('SYNAPSE_ADMIN_API_TOKEN'),
/*
|--------------------------------------------------------------------------
| Admin API Endpoint
|--------------------------------------------------------------------------
|
| This variable contains the admin endpoint for synapse.
|
*/
'admin_api_url' => env('SYNAPSE_ADMIN_API_URL'),
];

View File

@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('settings', function (Blueprint $table) {
$table->id();
$table->string('key')->unique();
$table->string('value');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('settings');
}
};

View File

@ -10,6 +10,7 @@
<flux:navlist variant="outline">
<flux:navlist.group :heading="__('Platform')" class="grid">
<flux:navlist.item icon="document-text" :href="route('dashboard')" :current="request()->routeIs('dashboard')" wire:navigate>{{ __('Applications') }}</flux:navlist.item>
<flux:navlist.item icon="wrench-screwdriver" :href="route('settings.synapse')" :current="request()->routeIs('settings.synapse')" wire:navigate>{{ __('Synapse') }}</flux:navlist.item>
</flux:navlist.group>
</flux:navlist>

View File

@ -0,0 +1,21 @@
<div class="flex items-start max-md:flex-col">
<div class="flex-1 self-stretch max-md:pt-6">
<div class="relative mb-6 w-full">
<flux:heading size="xl" level="1">{{ __('Settings') }}</flux:heading>
<flux:subheading size="lg" class="mb-6">{{ __('Manage synapse endpoint and access token') }}
</flux:subheading>
<flux:separator variant="subtle" />
</div>
<div class="flex flex-col gap-4 mt-5 w-full max-w-lg">
<flux:input wire:model="synapseEndpoint" placeholder="https://matrix.tld" label="Synapse Endpoint"
clearable />
<flux:input wire:model="synapseAccessToken" type="password" value="password" label="Access Token"
viewable />
<flux:button variant="primary" class="w-full" wire:click="save">Save</flux:button>
</div>
</div>
</div>

View File

@ -3,6 +3,7 @@
use App\Livewire\Settings\Appearance;
use App\Livewire\Settings\Password;
use App\Livewire\Settings\Profile;
use App\Livewire\Settings\Synapse;
use Illuminate\Support\Facades\Route;
Route::get('/', App\Livewire\ApplicationForm::class)->name('home');
@ -18,6 +19,7 @@ Route::middleware(['auth'])->group(function () {
Route::get('settings/profile', Profile::class)->name('settings.profile');
Route::get('settings/password', Password::class)->name('settings.password');
Route::get('settings/appearance', Appearance::class)->name('settings.appearance');
Route::get('settings/synapse', Synapse::class)->name('settings.synapse');
});
require __DIR__ . '/auth.php';