Add registration token
This commit is contained in:
parent
5a463656a7
commit
fd7d2f8068
@ -1,14 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
use Illuminate\Contracts\View\View;
|
|
||||||
|
|
||||||
class HomeController extends Controller
|
|
||||||
{
|
|
||||||
public function index(): View
|
|
||||||
{
|
|
||||||
return view('index');
|
|
||||||
}
|
|
||||||
}
|
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Livewire;
|
namespace App\Livewire;
|
||||||
|
|
||||||
use App\Models\Application;
|
use App\Models\Application;
|
||||||
|
use App\Services\SynapseService;
|
||||||
|
|
||||||
use Livewire\Component;
|
use Livewire\Component;
|
||||||
use Livewire\WithPagination;
|
use Livewire\WithPagination;
|
||||||
|
|
||||||
@ -12,6 +14,8 @@ class ApplicationList extends Component
|
|||||||
|
|
||||||
public $hideApproved = true;
|
public $hideApproved = true;
|
||||||
|
|
||||||
|
public $error = false;
|
||||||
|
|
||||||
public function updatingHideApproved()
|
public function updatingHideApproved()
|
||||||
{
|
{
|
||||||
$this->resetPage();
|
$this->resetPage();
|
||||||
@ -19,7 +23,14 @@ class ApplicationList extends Component
|
|||||||
|
|
||||||
public function approveApplication($uuid)
|
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)
|
public function rejectApplication($uuid)
|
||||||
|
@ -14,6 +14,7 @@ class Application extends Model
|
|||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'uuid',
|
'uuid',
|
||||||
'message',
|
'message',
|
||||||
|
'registration_token',
|
||||||
];
|
];
|
||||||
|
|
||||||
public function uploads()
|
public function uploads()
|
||||||
|
35
app/Services/SynapseService.php
Normal file
35
app/Services/SynapseService.php
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Services;
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Http;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
|
class SynapseService
|
||||||
|
{
|
||||||
|
public function createRegistrationToken(): ?string
|
||||||
|
{
|
||||||
|
$token = config('synapse.admin_api_token');
|
||||||
|
$endpoint = config('synapse.admin_api_url');
|
||||||
|
|
||||||
|
$response = Http::withHeaders([
|
||||||
|
'Authorization' => "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;
|
||||||
|
}
|
||||||
|
}
|
27
config/synapse.php
Normal file
27
config/synapse.php
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
<?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'),
|
||||||
|
|
||||||
|
];
|
@ -16,6 +16,7 @@ return new class extends Migration
|
|||||||
$table->uuid('uuid');
|
$table->uuid('uuid');
|
||||||
$table->tinyInteger('status')->default(0);
|
$table->tinyInteger('status')->default(0);
|
||||||
$table->string('message');
|
$table->string('message');
|
||||||
|
$table->string('registration_token')->nullable();
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@
|
|||||||
<div class="p-5 mb-4 dark:bg-red-950/50 rounded-lg">
|
<div class="p-5 mb-4 dark:bg-red-950/50 rounded-lg">
|
||||||
@endif
|
@endif
|
||||||
|
|
||||||
<flux:heading size="xl">Application Status</flux:heading>
|
<flux:heading size="xl">Application</flux:heading>
|
||||||
@php
|
@php
|
||||||
$status = [
|
$status = [
|
||||||
0 => 'Pending Review',
|
0 => 'Pending Review',
|
||||||
@ -21,21 +21,37 @@
|
|||||||
<strong>Status:</strong>
|
<strong>Status:</strong>
|
||||||
{{ $status[$application->status] }}
|
{{ $status[$application->status] }}
|
||||||
</p>
|
</p>
|
||||||
<p>
|
@if ($application->registration_token)
|
||||||
<strong>Created:</strong>
|
<p class="pt-2 pb-2">
|
||||||
{{ Carbon\Carbon::parse($application->created_at)->diffForHumans(['parts' => 2]) }}
|
<strong>Registration Token (valid until
|
||||||
</p>
|
{{ $application->updated_at->addWeek()->format('Y-m-d') }})</strong>
|
||||||
|
</p>
|
||||||
|
<flux:input class="mb-2" icon="key" value="{{ $application->registration_token }}" readonly
|
||||||
|
copyable />
|
||||||
|
To sign up, you should use <flux:link href="https://element.lolispace.moe">Element Web</flux:link> or
|
||||||
|
Element Desktop, as the authentication token is not compatible
|
||||||
|
with the mobile clients.
|
||||||
|
@endif
|
||||||
</flux:text>
|
</flux:text>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<h2 class="mt-4 font-semibold">Uploaded Photos:</h2>
|
@if (!$application->registration_token)
|
||||||
<div class="flex flex-wrap gap-4 mt-4">
|
<div class="p-5 mb-4 dark:bg-pink-950/50 rounded-lg">
|
||||||
@foreach ($application->uploads as $upload)
|
<flux:heading size="xl">Application</flux:heading>
|
||||||
<div>
|
<flux:text class="mt-2">
|
||||||
<img class="h-48 w-fit object-cover rounded-2xl hover:-translate-y-1 hover:scale-110 transition duration-300 ease-in-out"
|
{{ $application->message }}
|
||||||
src="{{ asset('storage/' . $upload->file_path) }}">
|
</flux:text>
|
||||||
</div>
|
</div>
|
||||||
@endforeach
|
|
||||||
</div>
|
<h2 class="mt-4 font-semibold">Uploaded Photos:</h2>
|
||||||
|
<div class="flex flex-wrap gap-4 mt-4">
|
||||||
|
@foreach ($application->uploads as $upload)
|
||||||
|
<div>
|
||||||
|
<img class="h-48 w-fit object-cover rounded-2xl hover:-translate-y-1 hover:scale-110 transition duration-300 ease-in-out"
|
||||||
|
src="{{ asset('storage/' . $upload->file_path) }}">
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user