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;
|
||||
|
||||
use App\Models\Application;
|
||||
use App\Services\SynapseService;
|
||||
|
||||
use Livewire\Component;
|
||||
use Livewire\WithPagination;
|
||||
|
||||
@ -12,6 +14,8 @@ class ApplicationList extends Component
|
||||
|
||||
public $hideApproved = true;
|
||||
|
||||
public $error = false;
|
||||
|
||||
public function updatingHideApproved()
|
||||
{
|
||||
$this->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)
|
||||
|
@ -14,6 +14,7 @@ class Application extends Model
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'message',
|
||||
'registration_token',
|
||||
];
|
||||
|
||||
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->tinyInteger('status')->default(0);
|
||||
$table->string('message');
|
||||
$table->string('registration_token')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -8,7 +8,7 @@
|
||||
<div class="p-5 mb-4 dark:bg-red-950/50 rounded-lg">
|
||||
@endif
|
||||
|
||||
<flux:heading size="xl">Application Status</flux:heading>
|
||||
<flux:heading size="xl">Application</flux:heading>
|
||||
@php
|
||||
$status = [
|
||||
0 => 'Pending Review',
|
||||
@ -21,21 +21,37 @@
|
||||
<strong>Status:</strong>
|
||||
{{ $status[$application->status] }}
|
||||
</p>
|
||||
<p>
|
||||
<strong>Created:</strong>
|
||||
{{ Carbon\Carbon::parse($application->created_at)->diffForHumans(['parts' => 2]) }}
|
||||
</p>
|
||||
@if ($application->registration_token)
|
||||
<p class="pt-2 pb-2">
|
||||
<strong>Registration Token (valid until
|
||||
{{ $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>
|
||||
</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>
|
||||
@if (!$application->registration_token)
|
||||
<div class="p-5 mb-4 dark:bg-pink-950/50 rounded-lg">
|
||||
<flux:heading size="xl">Application</flux:heading>
|
||||
<flux:text class="mt-2">
|
||||
{{ $application->message }}
|
||||
</flux:text>
|
||||
</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>
|
||||
|
Loading…
x
Reference in New Issue
Block a user