From d3967b37cdcdeaa26db0f0fbf37d3da961e4152c Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Dec 2023 14:52:14 -0600 Subject: [PATCH 01/16] this is a start, buttons not working? --- app/Http/Livewire/OauthClients.php | 39 +++ .../views/livewire/oauth-clients.blade.php | 250 ++++++++++++++++++ resources/views/settings/api.blade.php | 1 + 3 files changed, 290 insertions(+) create mode 100644 app/Http/Livewire/OauthClients.php create mode 100644 resources/views/livewire/oauth-clients.blade.php diff --git a/app/Http/Livewire/OauthClients.php b/app/Http/Livewire/OauthClients.php new file mode 100644 index 000000000..8e23f6335 --- /dev/null +++ b/app/Http/Livewire/OauthClients.php @@ -0,0 +1,39 @@ + app(ClientRepository::class)->activeForUser(auth()->user()->id), + ]); + } + + public function rules(): array + { + return [ + 'name' => 'required|string|max:255', + 'redirect' => 'required|url|max:255', + ]; + } + + public function createClient(): void + { + $this->validate(); + + //$newClient = ; + + $this->dispatchBrowserEvent('clientCreated', $newClient->accessToken); + } + + public function deleteClient($clientId): void + { + Auth::user()->clients()->find($clientId)->delete(); + } +} diff --git a/resources/views/livewire/oauth-clients.blade.php b/resources/views/livewire/oauth-clients.blade.php new file mode 100644 index 000000000..8f6c45cb8 --- /dev/null +++ b/resources/views/livewire/oauth-clients.blade.php @@ -0,0 +1,250 @@ + + + \ No newline at end of file diff --git a/resources/views/settings/api.blade.php b/resources/views/settings/api.blade.php index 5db4e1e7d..3c36c6a18 100644 --- a/resources/views/settings/api.blade.php +++ b/resources/views/settings/api.blade.php @@ -14,6 +14,7 @@ @section('content') @if (!config('app.lock_passwords'))
+
From 080d1961388fba8c5f5cfb6bdfcad01cf2e1f625 Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Dec 2023 16:41:25 -0600 Subject: [PATCH 02/16] buttons work now after style tags removed --- app/Http/Livewire/OauthClients.php | 9 +- .../views/livewire/oauth-clients.blade.php | 360 +++++++++--------- resources/views/settings/api.blade.php | 2 +- 3 files changed, 179 insertions(+), 192 deletions(-) diff --git a/app/Http/Livewire/OauthClients.php b/app/Http/Livewire/OauthClients.php index 8e23f6335..fadcd39fd 100644 --- a/app/Http/Livewire/OauthClients.php +++ b/app/Http/Livewire/OauthClients.php @@ -2,7 +2,7 @@ namespace App\Http\Livewire; -use Illuminate\Support\Facades\Auth; +use Laravel\Passport\Client; use Laravel\Passport\ClientRepository; use Livewire\Component; @@ -29,11 +29,12 @@ class OauthClients extends Component //$newClient = ; - $this->dispatchBrowserEvent('clientCreated', $newClient->accessToken); + //$this->dispatchBrowserEvent('clientCreated', $newClient->accessToken); } - public function deleteClient($clientId): void + public function deleteClient(Client $clientId): void { - Auth::user()->clients()->find($clientId)->delete(); + //->delete must be of type Client - thus the model binding + app(ClientRepository::class)->delete($clientId); } } diff --git a/resources/views/livewire/oauth-clients.blade.php b/resources/views/livewire/oauth-clients.blade.php index 8f6c45cb8..4c7be6c79 100644 --- a/resources/views/livewire/oauth-clients.blade.php +++ b/resources/views/livewire/oauth-clients.blade.php @@ -1,43 +1,30 @@ - - - \ No newline at end of file + + + + + \ No newline at end of file diff --git a/resources/views/settings/api.blade.php b/resources/views/settings/api.blade.php index 3c36c6a18..35ce89dd5 100644 --- a/resources/views/settings/api.blade.php +++ b/resources/views/settings/api.blade.php @@ -15,7 +15,7 @@ @if (!config('app.lock_passwords'))
- +{{-- --}}
@else From c28936fefb48aad1c37e03a90f22b8a52b5eb54e Mon Sep 17 00:00:00 2001 From: spencerrlongg Date: Tue, 5 Dec 2023 17:39:35 -0600 Subject: [PATCH 03/16] almost there... problem with update button --- app/Http/Livewire/OauthClients.php | 71 ++++++++-- .../views/livewire/oauth-clients.blade.php | 127 +++++++++++------- 2 files changed, 133 insertions(+), 65 deletions(-) diff --git a/app/Http/Livewire/OauthClients.php b/app/Http/Livewire/OauthClients.php index fadcd39fd..55ace8837 100644 --- a/app/Http/Livewire/OauthClients.php +++ b/app/Http/Livewire/OauthClients.php @@ -4,37 +4,80 @@ namespace App\Http\Livewire; use Laravel\Passport\Client; use Laravel\Passport\ClientRepository; +use Laravel\Passport\Passport; use Livewire\Component; class OauthClients extends Component { + public $name; + public $redirect; + public $editClientId; + public $editName; + public $editRedirect; + + protected $clientRepository; + + public function __construct() + { + $this->clientRepository = app(ClientRepository::class); + parent::__construct(); + } + public function render() { return view('livewire.oauth-clients', [ - 'clients' => app(ClientRepository::class)->activeForUser(auth()->user()->id), + 'clients' => $this->clientRepository->activeForUser(auth()->user()->id), ]); } - public function rules(): array - { - return [ - 'name' => 'required|string|max:255', - 'redirect' => 'required|url|max:255', - ]; - } - public function createClient(): void { - $this->validate(); + $this->validate([ + 'name' => 'required|string|max:255', + 'redirect' => 'required|url|max:255', + ]); - //$newClient = ; + $newClient = $this->clientRepository->create( + auth()->user()->id, + $this->name, + $this->redirect, + ); - //$this->dispatchBrowserEvent('clientCreated', $newClient->accessToken); + $this->dispatchBrowserEvent('clientCreated'); } public function deleteClient(Client $clientId): void { - //->delete must be of type Client - thus the model binding - app(ClientRepository::class)->delete($clientId); + // test for safety + // ->delete must be of type Client - thus the model binding + $this->clientRepository->delete($clientId); + } + + public function editClient(Client $editClientId): void + { + $this->editName = $editClientId->name; + $this->editRedirect = $editClientId->redirect; + + $this->dispatchBrowserEvent('editClient'); + } + + public function updateClient(Client $editClientId): void + { + $this->validate([ + 'editName' => 'required|string|max:255', + 'editRedirect' => 'required|url|max:255', + ]); + + $client = $this->clientRepository->find($editClientId->id); + if ($client->user_id == auth()->user()->id) { + $client->name = $this->editName; + $client->redirect = $this->editRedirect; + $client->save(); + } else { + // throw error + } + + $this->dispatchBrowserEvent('clientUpdated'); + } } diff --git a/resources/views/livewire/oauth-clients.blade.php b/resources/views/livewire/oauth-clients.blade.php index 4c7be6c79..b98eb6283 100644 --- a/resources/views/livewire/oauth-clients.blade.php +++ b/resources/views/livewire/oauth-clients.blade.php @@ -6,8 +6,8 @@ (Livewire) OAuth Clients - Create New Client @@ -55,7 +55,7 @@ Edit @@ -76,7 +76,7 @@ -