Update OauthClients component

This commit is contained in:
Marcus Moore 2024-06-04 15:37:41 -07:00
parent 5a9a231359
commit 296cf3e34b
No known key found for this signature in database
2 changed files with 9 additions and 19 deletions

View file

@ -19,21 +19,11 @@ class OauthClients extends Component
public $authorizationError; public $authorizationError;
protected $clientRepository;
protected $tokenRepository;
public function __construct()
{
$this->clientRepository = app(ClientRepository::class);
$this->tokenRepository = app(TokenRepository::class);
parent::__construct();
}
public function render() public function render()
{ {
return view('livewire.oauth-clients', [ return view('livewire.oauth-clients', [
'clients' => $this->clientRepository->activeForUser(auth()->user()->id), 'clients' => app(ClientRepository::class)->activeForUser(auth()->user()->id),
'authorized_tokens' => $this->tokenRepository->forUser(auth()->user()->id)->where('revoked', false), 'authorized_tokens' => app(TokenRepository::class)->forUser(auth()->user()->id)->where('revoked', false),
]); ]);
} }
@ -44,7 +34,7 @@ class OauthClients extends Component
'redirect' => 'required|url|max:255', 'redirect' => 'required|url|max:255',
]); ]);
$newClient = $this->clientRepository->create( $newClient = app(ClientRepository::class)->create(
auth()->user()->id, auth()->user()->id,
$this->name, $this->name,
$this->redirect, $this->redirect,
@ -58,7 +48,7 @@ class OauthClients extends Component
// test for safety // test for safety
// ->delete must be of type Client - thus the model binding // ->delete must be of type Client - thus the model binding
if ($clientId->user_id == auth()->user()->id) { if ($clientId->user_id == auth()->user()->id) {
$this->clientRepository->delete($clientId); app(ClientRepository::class)->delete($clientId);
} else { } else {
Log::warning('User ' . auth()->user()->id . ' attempted to delete client ' . $clientId->id . ' which belongs to user ' . $clientId->user_id); Log::warning('User ' . auth()->user()->id . ' attempted to delete client ' . $clientId->id . ' which belongs to user ' . $clientId->user_id);
$this->authorizationError = 'You are not authorized to delete this client.'; $this->authorizationError = 'You are not authorized to delete this client.';
@ -67,9 +57,9 @@ class OauthClients extends Component
public function deleteToken($tokenId): void public function deleteToken($tokenId): void
{ {
$token = $this->tokenRepository->find($tokenId); $token = app(TokenRepository::class)->find($tokenId);
if ($token->user_id == auth()->user()->id) { if ($token->user_id == auth()->user()->id) {
$this->tokenRepository->revokeAccessToken($tokenId); app(TokenRepository::class)->revokeAccessToken($tokenId);
} else { } else {
Log::warning('User ' . auth()->user()->id . ' attempted to delete token ' . $tokenId . ' which belongs to user ' . $token->user_id); Log::warning('User ' . auth()->user()->id . ' attempted to delete token ' . $tokenId . ' which belongs to user ' . $token->user_id);
$this->authorizationError = 'You are not authorized to delete this token.'; $this->authorizationError = 'You are not authorized to delete this token.';
@ -93,7 +83,7 @@ class OauthClients extends Component
'editRedirect' => 'required|url|max:255', 'editRedirect' => 'required|url|max:255',
]); ]);
$client = $this->clientRepository->find($editClientId->id); $client = app(ClientRepository::class)->find($editClientId->id);
if ($client->user_id == auth()->user()->id) { if ($client->user_id == auth()->user()->id) {
$client->name = $this->editName; $client->name = $this->editName;
$client->redirect = $this->editRedirect; $client->redirect = $this->editRedirect;

View file

@ -311,7 +311,7 @@
</div> </div>
<script> <script>
document.addEventListener('DOMContentLoaded', function() { document.addEventListener('DOMContentLoaded', function() {
window.livewire.on('openModal', () => { Livewire.on('openModal', () => {
$('#modal-create-client').modal('show').on('shown.bs.modal', function() { $('#modal-create-client').modal('show').on('shown.bs.modal', function() {
$(this).find('[autofocus]').focus(); $(this).find('[autofocus]').focus();
}); });