api-token-manager.blade.php 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. <div>
  2. <!-- Generate API Token -->
  3. <x-jet-form-section submit="createApiToken">
  4. <x-slot name="title">
  5. {{ __('Create API Token') }}
  6. </x-slot>
  7. <x-slot name="description">
  8. {{ __('API tokens allow third-party services to authenticate with our application on your behalf.') }}
  9. </x-slot>
  10. <x-slot name="form">
  11. <!-- Token Name -->
  12. <div class="col-span-6 sm:col-span-4">
  13. <x-jet-label for="name" value="{{ __('Token Name') }}" />
  14. <x-jet-input id="name" type="text" class="mt-1 block w-full" wire:model.defer="createApiTokenForm.name" autofocus />
  15. <x-jet-input-error for="name" class="mt-2" />
  16. </div>
  17. <!-- Token Permissions -->
  18. @if (Laravel\Jetstream\Jetstream::hasPermissions())
  19. <div class="col-span-6">
  20. <x-jet-label for="permissions" value="{{ __('Permissions') }}" />
  21. <div class="mt-2 grid grid-cols-1 md:grid-cols-2 gap-4">
  22. @foreach (Laravel\Jetstream\Jetstream::$permissions as $permission)
  23. <label class="flex items-center">
  24. <x-jet-checkbox wire:model.defer="createApiTokenForm.permissions" :value="$permission"/>
  25. <span class="ml-2 text-sm text-gray-600">{{ $permission }}</span>
  26. </label>
  27. @endforeach
  28. </div>
  29. </div>
  30. @endif
  31. </x-slot>
  32. <x-slot name="actions">
  33. <x-jet-action-message class="mr-3" on="created">
  34. {{ __('Created.') }}
  35. </x-jet-action-message>
  36. <x-jet-button>
  37. {{ __('Create') }}
  38. </x-jet-button>
  39. </x-slot>
  40. </x-jet-form-section>
  41. @if ($this->user->tokens->isNotEmpty())
  42. <x-jet-section-border />
  43. <!-- Manage API Tokens -->
  44. <div class="mt-10 sm:mt-0">
  45. <x-jet-action-section>
  46. <x-slot name="title">
  47. {{ __('Manage API Tokens') }}
  48. </x-slot>
  49. <x-slot name="description">
  50. {{ __('You may delete any of your existing tokens if they are no longer needed.') }}
  51. </x-slot>
  52. <!-- API Token List -->
  53. <x-slot name="content">
  54. <div class="space-y-6">
  55. @foreach ($this->user->tokens->sortBy('name') as $token)
  56. <div class="flex items-center justify-between">
  57. <div>
  58. {{ $token->name }}
  59. </div>
  60. <div class="flex items-center">
  61. @if ($token->last_used_at)
  62. <div class="text-sm text-gray-400">
  63. {{ __('Last used') }} {{ $token->last_used_at->diffForHumans() }}
  64. </div>
  65. @endif
  66. @if (Laravel\Jetstream\Jetstream::hasPermissions())
  67. <button class="cursor-pointer ml-6 text-sm text-gray-400 underline" wire:click="manageApiTokenPermissions({{ $token->id }})">
  68. {{ __('Permissions') }}
  69. </button>
  70. @endif
  71. <button class="cursor-pointer ml-6 text-sm text-red-500" wire:click="confirmApiTokenDeletion({{ $token->id }})">
  72. {{ __('Delete') }}
  73. </button>
  74. </div>
  75. </div>
  76. @endforeach
  77. </div>
  78. </x-slot>
  79. </x-jet-action-section>
  80. </div>
  81. @endif
  82. <!-- Token Value Modal -->
  83. <x-jet-dialog-modal wire:model="displayingToken">
  84. <x-slot name="title">
  85. {{ __('API Token') }}
  86. </x-slot>
  87. <x-slot name="content">
  88. <div>
  89. {{ __('Please copy your new API token. For your security, it won\'t be shown again.') }}
  90. </div>
  91. <x-jet-input x-ref="plaintextToken" type="text" readonly :value="$plainTextToken"
  92. class="mt-4 bg-gray-100 px-4 py-2 rounded font-mono text-sm text-gray-500 w-full"
  93. autofocus autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
  94. @showing-token-modal.window="setTimeout(() => $refs.plaintextToken.select(), 250)"
  95. />
  96. </x-slot>
  97. <x-slot name="footer">
  98. <x-jet-secondary-button wire:click="$set('displayingToken', false)" wire:loading.attr="disabled">
  99. {{ __('Close') }}
  100. </x-jet-secondary-button>
  101. </x-slot>
  102. </x-jet-dialog-modal>
  103. <!-- API Token Permissions Modal -->
  104. <x-jet-dialog-modal wire:model="managingApiTokenPermissions">
  105. <x-slot name="title">
  106. {{ __('API Token Permissions') }}
  107. </x-slot>
  108. <x-slot name="content">
  109. <div class="grid grid-cols-1 md:grid-cols-2 gap-4">
  110. @foreach (Laravel\Jetstream\Jetstream::$permissions as $permission)
  111. <label class="flex items-center">
  112. <x-jet-checkbox wire:model.defer="updateApiTokenForm.permissions" :value="$permission"/>
  113. <span class="ml-2 text-sm text-gray-600">{{ $permission }}</span>
  114. </label>
  115. @endforeach
  116. </div>
  117. </x-slot>
  118. <x-slot name="footer">
  119. <x-jet-secondary-button wire:click="$set('managingApiTokenPermissions', false)" wire:loading.attr="disabled">
  120. {{ __('Cancel') }}
  121. </x-jet-secondary-button>
  122. <x-jet-button class="ml-2" wire:click="updateApiToken" wire:loading.attr="disabled">
  123. {{ __('Save') }}
  124. </x-jet-button>
  125. </x-slot>
  126. </x-jet-dialog-modal>
  127. <!-- Delete Token Confirmation Modal -->
  128. <x-jet-confirmation-modal wire:model="confirmingApiTokenDeletion">
  129. <x-slot name="title">
  130. {{ __('Delete API Token') }}
  131. </x-slot>
  132. <x-slot name="content">
  133. {{ __('Are you sure you would like to delete this API token?') }}
  134. </x-slot>
  135. <x-slot name="footer">
  136. <x-jet-secondary-button wire:click="$toggle('confirmingApiTokenDeletion')" wire:loading.attr="disabled">
  137. {{ __('Cancel') }}
  138. </x-jet-secondary-button>
  139. <x-jet-danger-button class="ml-2" wire:click="deleteApiToken" wire:loading.attr="disabled">
  140. {{ __('Delete') }}
  141. </x-jet-danger-button>
  142. </x-slot>
  143. </x-jet-confirmation-modal>
  144. </div>