-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create API access token list and token page
- Loading branch information
1 parent
78f873c
commit 43c357d
Showing
11 changed files
with
316 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
121 changes: 121 additions & 0 deletions
121
resources/js/Pages/Admin/APIAccessTokens/APIAccessToken.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<script setup> | ||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'; | ||
import {Head, Link, usePage} from '@inertiajs/vue3'; | ||
import AdminTopNavigation from "@/Components/Admin/AdminTopNavigation.vue"; | ||
import {onMounted, ref} from "vue"; | ||
import Swal from "sweetalert2"; | ||
import dayjs from "dayjs"; | ||
import relativeTime from 'dayjs/plugin/relativeTime' | ||
import localizedFormat from 'dayjs/plugin/localizedFormat' | ||
import PrimaryButton from "@/Components/PrimaryButton.vue"; | ||
const $props = defineProps({ | ||
id: { | ||
required: true, | ||
type: Number, | ||
} | ||
}); | ||
const apiAccessToken = ref({}) | ||
onMounted(() => { | ||
getApiAccessToken() | ||
}) | ||
function dateFormat(dateTime) { | ||
dayjs.extend(relativeTime) | ||
dayjs.extend(localizedFormat) | ||
return dayjs(dateTime).fromNow() + ' (' + dayjs(dateTime).format('LLL') + ')' | ||
} | ||
function getApiAccessToken() { | ||
axios.get('/admin/user-personal-access-tokens/' + $props.id + '?cached=false&relations=user').then(response => { | ||
apiAccessToken.value = response.data.data | ||
}).catch(error => { | ||
console.log(error) | ||
}) | ||
} | ||
function revokeApiAccessToken() { | ||
Swal.fire({ | ||
title: "Are you sure you want to delete this token?", | ||
text: "This action cannot be undone, and the user will no longer be able to use this token. Please confirm if you wish to proceed.", | ||
icon: "warning", | ||
confirmButtonColor: "#3085d6", | ||
confirmButtonText: "Revoke this token", | ||
showCancelButton: true, | ||
}).then((result) => { | ||
if (result.isConfirmed) { | ||
axios.delete('/admin/user-personal-access-tokens/' + $props.id).then(response => { | ||
window.location.href = route('admin.api-access-tokens') | ||
}).catch(error => { | ||
console.log(error) | ||
}) | ||
} | ||
}); | ||
} | ||
function textFormat(ability) { | ||
return ability.replaceAll('-', ' ') | ||
} | ||
</script> | ||
|
||
<template> | ||
<Head title="API Access Token"/> | ||
|
||
<AuthenticatedLayout> | ||
<template #header> | ||
<AdminTopNavigation></AdminTopNavigation> | ||
</template> | ||
|
||
<div class="card"> | ||
|
||
<h2>{{ apiAccessToken.name }}</h2> | ||
|
||
</div> | ||
|
||
<div class="card"> | ||
<div class="card-header"> | ||
API Access Token details | ||
</div> | ||
|
||
<div class="text-xs">#{{ apiAccessToken.id }}</div> | ||
<div class="">{{ apiAccessToken.name }}</div> | ||
<div v-if="apiAccessToken.last_used_at" class="mt-2">Last used at: {{ dateFormat(apiAccessToken.last_used_at) }}</div> | ||
</div> | ||
|
||
<div class="card"> | ||
<div class="card-header"> | ||
Issued to user | ||
</div> | ||
|
||
<div v-if="apiAccessToken.user"> | ||
<Link :href="route('admin.user', apiAccessToken.tokenable_id)"> | ||
{{ apiAccessToken.user.name }} | ||
</Link> | ||
</div> | ||
</div> | ||
|
||
<div class="card"> | ||
<div class="card-header"> | ||
API Access Token abilities | ||
</div> | ||
|
||
<div v-if="apiAccessToken.abilities && apiAccessToken.abilities.length"> | ||
<div v-for="ability in apiAccessToken.abilities" class="py-1"> | ||
<div class="list-item ml-8"> | ||
{{ textFormat(ability) }} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="card"> | ||
<PrimaryButton @click="revokeApiAccessToken()"> | ||
Revoke this token | ||
</PrimaryButton> | ||
</div> | ||
</AuthenticatedLayout> | ||
</template> |
69 changes: 69 additions & 0 deletions
69
resources/js/Pages/Admin/APIAccessTokens/APIAccessTokens.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<script setup> | ||
import AuthenticatedLayout from '@/Layouts/AuthenticatedLayout.vue'; | ||
import {Head, Link} from '@inertiajs/vue3'; | ||
import AdminTopNavigation from "@/Components/Admin/AdminTopNavigation.vue"; | ||
import {onMounted, ref} from "vue"; | ||
import PaginatorComponent from "@/Components/Admin/PaginatorComponent.vue"; | ||
const apiAccessTokens = ref({}) | ||
onMounted(() => { | ||
getApiAccessTokens() | ||
}) | ||
function getApiAccessTokens(page = 1) { | ||
axios.get('/admin/user-personal-access-tokens?cached=false&page=' + page + '&relations=user&orderBy=id,desc').then(response => { | ||
apiAccessTokens.value = response.data.data | ||
}).catch(error => { | ||
console.log(error) | ||
}) | ||
} | ||
</script> | ||
|
||
<template> | ||
<Head title="API Access Tokens"/> | ||
|
||
<AuthenticatedLayout> | ||
<template #header> | ||
<AdminTopNavigation></AdminTopNavigation> | ||
</template> | ||
|
||
|
||
<div class=" card"> | ||
<div v-if="apiAccessTokens.data && apiAccessTokens.data.length"> | ||
<Link :href="route('admin.api-access-token', token.id)" v-for="token in apiAccessTokens.data" class="hover:no-underline hover:opacity-75"> | ||
<div class="border-b flex justify-between items-center py-2 sm:p-2"> | ||
<div> | ||
|
||
<div class="font-bold"> | ||
<span class="text-xs opacity-25"> | ||
#{{ token.id }} | ||
</span> | ||
{{ token.name }} | ||
</div> | ||
<div v-if="token.user" class="text-sm"> | ||
Issued to: {{ token.user.name }} | ||
</div> | ||
</div> | ||
<div class="text-2xl"> | ||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="1.5" stroke="currentColor" class="size-6"> | ||
<path stroke-linecap="round" stroke-linejoin="round" d="m8.25 4.5 7.5 7.5-7.5 7.5" /> | ||
</svg> | ||
|
||
</div> | ||
</div> | ||
</Link> | ||
</div> | ||
|
||
<div class="flex justify-end items-center mt-4"> | ||
<div class="w-full lg:w-1/3"> | ||
<PaginatorComponent | ||
@setDataPage="getApiAccessTokens" | ||
:pagination-data="apiAccessTokens"></PaginatorComponent> | ||
</div> | ||
</div> | ||
</div> | ||
</AuthenticatedLayout> | ||
</template> |
Oops, something went wrong.