'', 'permissions' => [], ]; /** * Indicates if the plain text token is being displayed to the user. * * @var bool */ public $displayingToken = false; /** * The plain text token value. * * @var string|null */ public $plainTextToken; /** * Indicates if the user is currently managing an API token's permissions. * * @var bool */ public $managingApiTokenPermissions = false; /** * The token that is currently having its permissions managed. * * @var \Laravel\Sanctum\PersonalAccessToken|null */ public $managingPermissionsFor; /** * The update API token form state. * * @var array */ public $updateApiTokenForm = [ 'permissions' => [], ]; /** * Indicates if the application is confirming if an API token should be deleted. * * @var bool */ public $confirmingApiTokenDeletion = false; /** * The ID of the API token being deleted. * * @var int */ public $apiTokenIdBeingDeleted; /** * Mount the component. * * @return void */ public function mount() { // } /** * Create a new API token. * * @return void */ public function createApiToken() { $this->resetErrorBag(); Validator::make([ 'name' => $this->createApiTokenForm['name'], ], [ 'name' => ['required', 'string', 'max:255'], ])->validateWithBag('createApiToken'); $this->displayTokenValue($this->user->createToken( $this->createApiTokenForm['name'] )); $this->createApiTokenForm['name'] = ''; $this->dispatch('created'); } /** * Display the token value to the user. * * @param \Laravel\Sanctum\NewAccessToken $token * @return void */ protected function displayTokenValue($token) { $this->displayingToken = true; $this->plainTextToken = explode('|', $token->plainTextToken, 2)[1]; } /** * Allow the given token's permissions to be managed. * * @param int $tokenId * @return void */ public function manageApiTokenPermissions($tokenId) { $this->managingApiTokenPermissions = true; $this->managingPermissionsFor = $this->user->tokens()->where( 'id', $tokenId )->firstOrFail(); $this->updateApiTokenForm['permissions'] = $this->managingPermissionsFor->abilities; } /** * Update the API token's permissions. * * @return void */ public function updateApiToken() { $this->managingPermissionsFor->forceFill([ 'abilities' => [], ])->save(); $this->managingApiTokenPermissions = false; } /** * Confirm that the given API token should be deleted. * * @param int $tokenId * @return void */ public function confirmApiTokenDeletion($tokenId) { $this->confirmingApiTokenDeletion = true; $this->apiTokenIdBeingDeleted = $tokenId; } /** * Delete the API token. * * @return void */ public function deleteApiToken() { $this->user->tokens()->where('id', $this->apiTokenIdBeingDeleted)->first()->delete(); $this->user->load('tokens'); $this->confirmingApiTokenDeletion = false; $this->managingPermissionsFor = null; } /** * Get the current user of the application. * * @return mixed */ public function getUserProperty() { return Auth::user(); } }; ?>
{{-- Generate API Token --}} {{ __('Create API Token') }} {{ __('API tokens allow third-party services to authenticate with Investbrain on your behalf.') }} {{-- Token Name --}}
{{-- Token Permissions --}} @if (false)
@endif {{-- Token Value Modal --}}
{{ __('Please copy your new API token. For your security, it won\'t be shown again.') }}
{{ __('Close') }}
{{ __('Created.') }} {{ __('Create') }}
@if ($this->user->tokens->isNotEmpty()) {{-- Manage API Tokens --}}
{{ __('Manage API Tokens') }} {{ __('You may delete any of your existing tokens if they are no longer needed.') }} {{-- API Token List --}}
@foreach ($this->user->tokens->sortBy('name') as $token)
{{ $token->name }}
@if ($token->last_used_at)
{{ __('Last used') }} {{ $token->last_used_at->diffForHumans() }}
@endif @if (false) @endif
@endforeach
@endif {{-- API Token Permissions Modal --}} {{ __('API Token Permissions') }}
@foreach ([] as $label => $permission) @endforeach
{{ __('Cancel') }} {{ __('Save') }}
{{-- Delete Token Confirmation Modal --}} {{ __('Delete API Token') }} {{ __('Are you sure you would like to delete this API token?') }} {{ __('Cancel') }} {{ __('Delete') }}