From 331b546480898a621f85bc49a41ea65b6ae6444a Mon Sep 17 00:00:00 2001 From: Bernd Storath <999999bst@gmail.com> Date: Fri, 23 Aug 2024 15:17:51 +0200 Subject: [PATCH] update frontend --- src/app.vue | 4 +++ src/components/Client/ExpireDate.vue | 38 ++++++++++++++++-------- src/components/Client/OneTimeLink.vue | 19 +++++++----- src/components/Client/OneTimeLinkBtn.vue | 3 +- src/components/Clients/Sort.vue | 12 ++++---- src/i18n.config.ts | 12 ++++++++ src/pages/login.vue | 8 +++-- src/server/utils/WireGuard.ts | 2 +- src/stores/auth.ts | 4 +-- src/stores/clients.ts | 2 +- src/stores/global.ts | 29 +++++++++++++++++- src/stores/modal.ts | 2 +- src/utils/api.ts | 2 +- 13 files changed, 101 insertions(+), 36 deletions(-) diff --git a/src/app.vue b/src/app.vue index 7b69a966..860b7031 100644 --- a/src/app.vue +++ b/src/app.vue @@ -11,6 +11,10 @@ const globalStore = useGlobalStore(); globalStore.fetchTrafficStats(); globalStore.fetchChartType(); globalStore.fetchRelease(); +globalStore.fetchOneTimeLinks(); +globalStore.fetchSortClients(); +globalStore.fetchExpireTime(); +globalStore.fetchRememberMe(); useHead({ bodyAttrs: { class: 'bg-gray-50 dark:bg-neutral-800', diff --git a/src/components/Client/ExpireDate.vue b/src/components/Client/ExpireDate.vue index d129d2ed..0381e4b8 100644 --- a/src/components/Client/ExpireDate.vue +++ b/src/components/Client/ExpireDate.vue @@ -7,40 +7,37 @@ {{ client.expiredAt | expiredDateFormat }}{{ expiredDateFormat(client.expireAt) }} $refs['client-' + client.id + '-expire'][0].select(), - 1 - ); + nextTick(() => clientExpireDateInput?.select()); " - class="cursor-pointer opacity-0 group-hover:opacity-100 transition-opacity" > (); const globalStore = useGlobalStore(); const clientsStore = useClientsStore(); +const clientEditExpireDate = ref(null); +const clientEditExpireDateId = ref(null); +const { t, locale } = useI18n(); + +const clientExpireDateInput = ref(null); function updateClientExpireDate( client: LocalClient, @@ -76,4 +78,14 @@ function updateClientExpireDate( .catch((err) => alert(err.message || err.toString())) .finally(() => clientsStore.refresh().catch(console.error)); } + +function expiredDateFormat(value: string | null) { + if (value === null) return t('Permanent'); + const dateTime = new Date(value); + return dateTime.toLocaleDateString(locale.value, { + year: 'numeric', + month: 'long', + day: 'numeric', + }); +} diff --git a/src/components/Client/OneTimeLink.vue b/src/components/Client/OneTimeLink.vue index af193d8b..2fb0a858 100644 --- a/src/components/Client/OneTimeLink.vue +++ b/src/components/Client/OneTimeLink.vue @@ -1,21 +1,26 @@ - {{ document.location.protocol }}//{{ document.location.host }}/cnf/{{ - client.oneTimeLink - }} + {{ path }} diff --git a/src/components/Client/OneTimeLinkBtn.vue b/src/components/Client/OneTimeLinkBtn.vue index be57abf5..284a17d1 100644 --- a/src/components/Client/OneTimeLinkBtn.vue +++ b/src/components/Client/OneTimeLinkBtn.vue @@ -1,6 +1,6 @@ - + diff --git a/src/i18n.config.ts b/src/i18n.config.ts index a582b697..aa9cad63 100644 --- a/src/i18n.config.ts +++ b/src/i18n.config.ts @@ -40,6 +40,12 @@ export default defineI18nConfig(() => ({ backup: 'Backup', titleRestoreConfig: 'Restore your configuration', titleBackupConfig: 'Backup your configuration', + rememberMe: 'Remember me', + titleRememberMe: 'Stay logged after closing the browser', + sort: 'Sort', + ExpireDate: 'Expire Date', + Permanent: 'Permanent', + OneTimeLink: 'Generate short one time link', }, ua: { name: 'Ім`я', @@ -118,6 +124,12 @@ export default defineI18nConfig(() => ({ backup: 'Резервная копия', titleRestoreConfig: 'Восстановить конфигурацию', titleBackupConfig: 'Создать резервную копию конфигурации', + rememberMe: 'Запомнить меня', + titleRememberMe: 'Оставаться в системе после закрытия браузера', + sort: 'Сортировка', + ExpireDate: 'Дата истечения срока', + Permanent: 'Бессрочно', + OneTimeLink: 'Создать короткую одноразовую ссылку', }, tr: { // Müslüm Barış Korkmazer @babico diff --git a/src/pages/login.vue b/src/pages/login.vue index b9f91f0b..ee7840b1 100644 --- a/src/pages/login.vue +++ b/src/pages/login.vue @@ -28,11 +28,11 @@ /> - + const authenticating = ref(false); +const remember = ref(false); const password = ref(null); const authStore = useAuthStore(); +const globalStore = useGlobalStore(); async function login(e: Event) { e.preventDefault(); @@ -87,7 +89,7 @@ async function login(e: Event) { authenticating.value = true; try { - const res = await authStore.login(password.value); + const res = await authStore.login(password.value, remember.value); if (res) { await navigateTo('/'); } diff --git a/src/server/utils/WireGuard.ts b/src/server/utils/WireGuard.ts index f3c3ed70..d9aa09c0 100644 --- a/src/server/utils/WireGuard.ts +++ b/src/server/utils/WireGuard.ts @@ -166,7 +166,7 @@ ${ publicKey: client.publicKey, createdAt: new Date(client.createdAt), updatedAt: new Date(client.updatedAt), - expiredAt: client.expireAt !== null ? new Date(client.expireAt) : null, + expireAt: client.expireAt !== null ? new Date(client.expireAt) : null, allowedIPs: client.allowedIPs, oneTimeLink: client.oneTimeLink ?? null, oneTimeLinkExpiresAt: client.oneTimeLinkExpiresAt ?? null, diff --git a/src/stores/auth.ts b/src/stores/auth.ts index b3ecf675..4e6470ca 100644 --- a/src/stores/auth.ts +++ b/src/stores/auth.ts @@ -4,8 +4,8 @@ export const useAuthStore = defineStore('Auth', () => { /** * @throws if unsuccessful */ - async function login(password: string) { - const response = await api.createSession({ password }); + async function login(password: string, remember: boolean) { + const response = await api.createSession({ password, remember }); requiresPassword.value = response.requiresPassword; return true as const; } diff --git a/src/stores/clients.ts b/src/stores/clients.ts index a0565437..65b24d64 100644 --- a/src/stores/clients.ts +++ b/src/stores/clients.ts @@ -108,7 +108,7 @@ export const useClientsStore = defineStore('Clients', () => { }; }); - if (globalStore.enableSortClient) { + if (globalStore.enableSortClient && transformedClients !== undefined) { transformedClients = sortByProperty( transformedClients, 'name', diff --git a/src/stores/global.ts b/src/stores/global.ts index 4e736576..33a5a4f8 100644 --- a/src/stores/global.ts +++ b/src/stores/global.ts @@ -9,7 +9,8 @@ export const useGlobalStore = defineStore('Global', () => { ); const uiTrafficStats = ref(false); const rememberMeEnabled = ref(false); - + const enableExpireTime = ref(false); + const enableOneTimeLinks = ref(false); const enableSortClient = ref(false); const sortClient = ref(true); // Sort clients by name, true = asc, false = desc @@ -46,6 +47,26 @@ export const useGlobalStore = defineStore('Global', () => { uiTrafficStats.value = trafficStats.value ?? false; } + async function fetchOneTimeLinks() { + const { data: oneTimeLinks } = await api.getEnableOneTimeLinks(); + enableOneTimeLinks.value = oneTimeLinks.value ?? false; + } + + async function fetchSortClients() { + const { data: sortClients } = await api.getSortClients(); + enableSortClient.value = sortClients.value ?? false; + } + + async function fetchExpireTime() { + const { data: expireTime } = await api.getEnableExpireTime(); + enableExpireTime.value = expireTime.value ?? false; + } + + async function fetchRememberMe() { + const { data: rememberMe } = await api.getRememberMeEnabled(); + rememberMeEnabled.value = rememberMe.value ?? false; + } + const updateCharts = computed(() => { return uiChartType.value > 0 && uiShowCharts.value; }); @@ -58,8 +79,14 @@ export const useGlobalStore = defineStore('Global', () => { rememberMeEnabled, enableSortClient, sortClient, + enableExpireTime, + enableOneTimeLinks, fetchRelease, fetchChartType, fetchTrafficStats, + fetchOneTimeLinks, + fetchSortClients, + fetchExpireTime, + fetchRememberMe, }; }); diff --git a/src/stores/modal.ts b/src/stores/modal.ts index f66066be..99e5c3ca 100644 --- a/src/stores/modal.ts +++ b/src/stores/modal.ts @@ -5,7 +5,7 @@ export const useModalStore = defineStore('Modal', () => { const clientDelete = ref(null); const clientCreate = ref(null); const clientCreateName = ref(''); - const clientExpireDate = ref(null); + const clientExpireDate = ref(null); const qrcode = ref(null); function createClient() { diff --git a/src/utils/api.ts b/src/utils/api.ts index fd6f644e..a3a0f133 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -78,7 +78,7 @@ class API { expireDate, }: { name: string; - expireDate: string; + expireDate: string | null; }) { return $fetch('/api/wireguard/client', { method: 'post',