An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
Add admin dashboard route and view
Andras Bacsai08a729dc7b58
diff --git a/app/Livewire/Admin/Index.php b/app/Livewire/Admin/Index.phpnew file mode 100644index 0000000000..174ce9e0f7--- /dev/null+++ b/app/Livewire/Admin/Index.php@@ -0,0 +1,41 @@+<?php++namespace App\Livewire\Admin;++use App\Models\User;+use Illuminate\Support\Facades\Crypt;+use Livewire\Component;++class Index extends Component+{+ public $users = [];+ public function mount()+ {+ if (auth()->user()->isInstanceAdmin() === false && session('adminToken') === null) {+ return redirect()->route('dashboard');+ }+ $this->users = User::whereHas('teams', function ($query) {+ $query->whereRelation('subscription', 'stripe_subscription_id', '!=', null);+ })->get();+ }+ public function switchUser(int $user_id)+ {+ $user = User::find($user_id);+ auth()->login($user);++ if ($user_id === 0) {+ session()->forget('adminToken');+ } else {+ $token_payload = [+ 'valid' => true,+ ];+ $token = Crypt::encrypt($token_payload);+ session(['adminToken' => $token]);+ }+ return refreshSession();+ }+ public function render()+ {+ return view('livewire.admin.index');+ }+}diff --git a/resources/views/components/navbar-subscription.blade.php b/resources/views/components/navbar-subscription.blade.phpindex 2e587be382..f1f68b50e9 100644--- a/resources/views/components/navbar-subscription.blade.php+++ b/resources/views/components/navbar-subscription.blade.php@@ -27,21 +27,17 @@<li title="Send us feedback or get help!" class="fixed top-0 right-0 p-2 px-4 pt-4 mt-auto text-xs"><div class="justify-center" wire:click="help" onclick="help.showModal()"><svg class="icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">- <path fill="currentColor" d="M140 180a12 12 0 1 1-12-12a12 12 0 0 1 12 12M128 72c-22.06 0-40 16.15-40 36v4a8 8 0 0 0 16 0v-4c0-11 10.77-20 24-20s24 9 24 20s-10.77 20-24 20a8 8 0 0 0-8 8v8a8 8 0 0 0 16 0v-.72c18.24-3.35 32-17.9 32-35.28c0-19.85-17.94-36-40-36m104 56A104 104 0 1 1 128 24a104.11 104.11 0 0 1 104 104m-16 0a88 88 0 1 0-88 88a88.1 88.1 0 0 0 88-88"/>+ <path fill="currentColor"+ d="M140 180a12 12 0 1 1-12-12a12 12 0 0 1 12 12M128 72c-22.06 0-40 16.15-40 36v4a8 8 0 0 0 16 0v-4c0-11 10.77-20 24-20s24 9 24 20s-10.77 20-24 20a8 8 0 0 0-8 8v8a8 8 0 0 0 16 0v-.72c18.24-3.35 32-17.9 32-35.28c0-19.85-17.94-36-40-36m104 56A104 104 0 1 1 128 24a104.11 104.11 0 0 1 104 104m-16 0a88 88 0 1 0-88 88a88.1 88.1 0 0 0 88-88" /></svg></div></li><li class="pb-6" title="Logout">- <form action="/logout" method="POST" class=" hover:bg-transparent">+ <form action="/logout" method="POST" class="hover:bg-transparent">@csrf<button class="flex items-center gap-2 rounded-none hover:text-white hover:bg-transparent">- <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24" stroke-width="1.5"- stroke="currentColor" fill="none" stroke-linecap="round" stroke-linejoin="round">- <path stroke="none" d="M0 0h24v24H0z" fill="none" />- <path d="M13 12v.01" />- <path d="M3 21h18" />- <path d="M5 21v-16a2 2 0 0 1 2 -2h7.5m2.5 10.5v7.5" />- <path d="M14 7h7m-3 -3l3 3l-3 3" />+ <svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">+ <path fill="currentColor" d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2a9.985 9.985 0 0 1 8 4h-2.71a8 8 0 1 0 .001 12h2.71A9.985 9.985 0 0 1 12 22m7-6v-3h-8v-2h8V8l5 4z"/></svg></button></form>diff --git a/resources/views/components/navbar.blade.php b/resources/views/components/navbar.blade.phpindex 9ff10d8186..e4cafb6b9d 100644--- a/resources/views/components/navbar.blade.php+++ b/resources/views/components/navbar.blade.php@@ -139,26 +139,19 @@</a></li>@endif- <li title="Logout" class="hover:bg-coolgray-200">- <form action="/logout" method="POST" class=" hover:bg-transparent">- @csrf- <button type="submit" class="rounded-none hover:text-white hover:bg-transparent">- <svg xmlns="http://www.w3.org/2000/svg" class="icon" viewBox="0 0 24 24"- stroke-width="1.5" stroke="currentColor" fill="none" stroke-linecap="round"- stroke-linejoin="round">- <path stroke="none" d="M0 0h24v24H0z" fill="none" />- <path d="M13 12v.01" />- <path d="M3 21h18" />- <path d="M5 21v-16a2 2 0 0 1 2 -2h7.5m2.5 10.5v7.5" />- <path d="M14 7h7m-3 -3l3 3l-3 3" />- </svg>- </button>- Logout- </form>- </li>+</ul></details>-+ @if (isCloud())+ <li title="Admin">+ <a class="hover:bg-transparent" href="/admin">+ <svg class="text-pink-600 icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg">+ <path fill="currentColor"+ d="M177.62 159.6a52 52 0 0 1-34 34a12.2 12.2 0 0 1-3.6.55a12 12 0 0 1-3.6-23.45a28 28 0 0 0 18.32-18.32a12 12 0 0 1 22.9 7.2ZM220 144a92 92 0 0 1-184 0c0-28.81 11.27-58.18 33.48-87.28a12 12 0 0 1 17.9-1.33l19.69 19.11L127 19.89a12 12 0 0 1 18.94-5.12C168.2 33.25 220 82.85 220 144m-24 0c0-41.71-30.61-78.39-52.52-99.29l-20.21 55.4a12 12 0 0 1-19.63 4.5L80.71 82.36C67 103.38 60 124.06 60 144a68 68 0 0 0 136 0" />+ </svg>+ </a>+ </li>+ @endif<div class="flex-1"></div>@if (isInstanceAdmin() && !isCloud())@persist('upgrade')@@ -178,7 +171,7 @@</a></li>- <li title="Send us feedback or get help!" class="pb-6 hover:bg-transparent">+ <li title="Send us feedback or get help!" class="hover:bg-transparent"><div class="justify-center" wire:click="help" onclick="help.showModal()"><svg class="icon" viewBox="0 0 256 256" xmlns="http://www.w3.org/2000/svg"><path fill="currentColor"@@ -186,7 +179,16 @@</svg></div></li>-+ <form action="/logout" method="POST" class="hover:bg-transparent">+ <li title="Logout" class="mb-6 hover:transparent">+ @csrf+ <button type="submit" class="rounded-none hover:text-white hover:bg-transparent">+ <svg class="icon" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">+ <path fill="currentColor" d="M12 22C6.477 22 2 17.523 2 12S6.477 2 12 2a9.985 9.985 0 0 1 8 4h-2.71a8 8 0 1 0 .001 12h2.71A9.985 9.985 0 0 1 12 22m7-6v-3h-8v-2h8V8l5 4z"/>+ </svg>+ </button>+ </li>+ </form></ul></nav>@endauthdiff --git a/resources/views/livewire/admin/index.blade.php b/resources/views/livewire/admin/index.blade.phpnew file mode 100644index 0000000000..d2304ade4b--- /dev/null+++ b/resources/views/livewire/admin/index.blade.php@@ -0,0 +1,17 @@+<div>+ <h1>Admin Dashboard</h1>+ <h3 class="pt-4">Who am I now?</h3>+ {{ auth()->user()->name }}+ <h3 class="pt-4">Users</h3>+ <div class="flex flex-wrap gap-2">+ <div class="w-96 box" wire:click="switchUser('0')">+ Root+ </div>+ @foreach ($users as $user)+ <div class="w-96 box" wire:click="switchUser('{{ $user->id }}')">+ <p>{{ $user->name }}</p>+ <p>{{ $user->email }}</p>+ </div>+ @endforeach+ </div>+</div>diff --git a/routes/web.php b/routes/web.phpindex f32d88d7ab..bb3ca6e345 100644--- a/routes/web.php+++ b/routes/web.php@@ -11,6 +11,8 @@ use Illuminate\Support\Facades\Route;use App\Http\Controllers\Controller;use App\Http\Controllers\MagicController;++use App\Livewire\Admin\Index as AdminIndex;use App\Livewire\Dev\Compose as Compose;use App\Livewire\Dashboard;@@ -77,6 +79,9 @@ use App\Livewire\Waitlist\Index as WaitlistIndex;if (isDev()) {Route::get('/dev/compose', Compose::class)->name('dev.compose');}+if (isCloud()) {+ Route::get('/admin', AdminIndex::class)->name('admin.index');+}Route::post('/forgot-password', [Controller::class, 'forgot_password'])->name('password.forgot');Route::get('/api/v1/test/realtime', [Controller::class, 'realtime_test'])->middleware('auth');