mirror of
https://github.com/Bubka/2FAuth.git
synced 2024-12-12 02:00:47 +01:00
1 line
11 KiB
Plaintext
1 line
11 KiB
Plaintext
|
{"version":3,"file":"OAuth-B7q39fAh.js","sources":["../../../resources/js/views/settings/OAuth.vue"],"sourcesContent":["<script setup>\n import Form from '@/components/formElements/Form'\n import userService from '@/services/userService'\n import SettingTabs from '@/layouts/SettingTabs.vue'\n import { useNotifyStore } from '@/stores/notify'\n import { UseColorMode } from '@vueuse/components'\n import { useUserStore } from '@/stores/user'\n import Spinner from '@/components/Spinner.vue'\n\n const $2fauth = inject('2fauth')\n const notify = useNotifyStore()\n const user = useUserStore()\n const returnTo = useStorage($2fauth.prefix + 'returnTo', 'accounts')\n const { copy } = useClipboard({ legacy: true })\n\n const tokens = ref([])\n const isFetching = ref(false)\n const createPATModalIsVisible = ref(false)\n const visibleToken = ref(null)\n const visibleTokenId = ref(null)\n\n const isDisabled = computed(() => {\n return (appSettings.enableSso && appSettings.useSsoOnly) || user.authenticated_by_proxy\n })\n\n onMounted(() => {\n fetchTokens()\n })\n\n const form = reactive(new Form({\n name : '',\n }))\n\n /**\n * Get all groups from backend\n */\n function fetchTokens() {\n isFetching.value = true\n\n userService.getPersonalAccessTokens({returnError: true})\n .then(response => {\n tokens.value = []\n response.data.forEach((data) => {\n if (data.id === visibleTokenId.value) {\n data.value = visibleToken.value\n tokens.value.unshift(data)\n }\n else {\n tokens.value.push(data)\n }\n })\n })\n .catch(error => {\n if( error.response.status === 405 ) {\n // The backend returns a 405 response if the user is authenticated by a reverse proxy\n // or if SSO only is enabled.\n // The form is already disabled (see isDisabled) so we do nothing more here\n }\n else {\n notify.error(error)\n }\n })\n .finally(() => {\n isFetching.value = false\n visibleTokenId.value = null\n visibleToken.value = null\n })\n }\n\n\n /**\n * Open the PAT creation view\n */\n function showPATcreationForm() {\n clearTokenValues()\n\n if (isDisabled.value) {\n notify.warn({ text: trans('errors.unsupported_with_reverseproxy') })\n }\n else createPATModalIsVisible.value = true\n }\n \n /**\n * Generate a fresh token\n */\n function generatePAToken() {\n form.post('/oauth/personal-access-tokens')\n .then(response => {\n visibleToken.value = response.data.accessToken\n visibleTokenId.value = response.data.token.id\n fetchTokens()\n createPATModalIsVisible.value = false\n form.reset()\n })\n }\n\n /**\n * revoke a token (after confirmation)\n */\n function revokeToken(tokenId) {\n if(confirm(trans('settings.confirm.revoke'))) {\n userService.deletePersonalAccessToken(tokenId)\n .then(response => {\n // Remove the revoked token from the collection\n tokens.value = tokens.value.filter(a => a.id !== tokenId)\n notify.success({ text: trans('settings.token_revoked') })\n })\n }\n }\n\n /**\n * Removes visible tokens data\n */\n function clearTokenValues() {\n tokens.value.forEach(token => {\n token.value = null\n })\n visibleToken.value = null\n }\n\n /**\n * Copies data to clipboard and notifies on success\n */\n function copyToClipboard(data) {\n copy(data)\n notify.success({ text: trans('commons.copied_to_clipboard') })\n }\n\n /**\n * Closes & resets the PAT creation form \n
|