✨ File encryption
✨ Shared login status across sites
This commit is contained in:
@@ -27,18 +27,14 @@ import { NLayout, NLayoutHeader, NLayoutContent, NButton, NDropdown, NIcon } fro
|
||||
import {
|
||||
LogInOutlined,
|
||||
PersonAddAlt1Outlined,
|
||||
LogOutOutlined,
|
||||
PersonOutlineRound,
|
||||
} from '@vicons/material'
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { useRoute, useRouter } from 'vue-router'
|
||||
import { useServicesStore } from '@/stores/services'
|
||||
|
||||
const userStore = useUserStore()
|
||||
const route = useRoute()
|
||||
const router = useRouter()
|
||||
|
||||
// Initialize user state on component mount
|
||||
userStore.initialize()
|
||||
|
||||
const hideUserMenu = computed(() => {
|
||||
return ['captcha', 'spells', 'login', 'create-account'].includes(route.name as string)
|
||||
@@ -71,31 +67,22 @@ const userOptions = computed(() => [
|
||||
h(NIcon, null, {
|
||||
default: () => h(PersonOutlineRound),
|
||||
}),
|
||||
},
|
||||
{
|
||||
label: 'Logout',
|
||||
key: 'logout',
|
||||
icon: () =>
|
||||
h(NIcon, null, {
|
||||
default: () => h(LogOutOutlined),
|
||||
}),
|
||||
},
|
||||
}
|
||||
])
|
||||
|
||||
const servicesStore = useServicesStore()
|
||||
|
||||
function handleGuestMenuSelect(key: string) {
|
||||
if (key === 'login') {
|
||||
router.push('/login')
|
||||
window.open(servicesStore.getSerivceUrl('DysonNetwork.Pass', 'login')!, '_blank')
|
||||
} else if (key === 'create-account') {
|
||||
router.push('/create-account')
|
||||
window.open(servicesStore.getSerivceUrl('DysonNetwork.Pass', 'create-account')!, '_blank')
|
||||
}
|
||||
}
|
||||
|
||||
function handleUserMenuSelect(key: string) {
|
||||
if (key === 'logout') {
|
||||
userStore.logout()
|
||||
router.push('/login')
|
||||
} else if (key === 'profile') {
|
||||
router.push('/accounts/me') // Assuming you have a profile page
|
||||
if (key === 'profile') {
|
||||
window.open(servicesStore.getSerivceUrl('DysonNetwork.Pass', 'accounts/me')!, '_blank')
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
@@ -6,6 +6,7 @@ import { NGlobalStyle, NConfigProvider, NMessageProvider, lightTheme, darkTheme
|
||||
import { usePreferredDark } from '@vueuse/core'
|
||||
import { useUserStore } from './stores/user'
|
||||
import { onMounted } from 'vue'
|
||||
import { useServicesStore } from './stores/services'
|
||||
|
||||
const themeOverrides = {
|
||||
common: {
|
||||
@@ -20,9 +21,13 @@ const themeOverrides = {
|
||||
const isDark = usePreferredDark()
|
||||
|
||||
const userStore = useUserStore()
|
||||
const servicesStore = useServicesStore()
|
||||
|
||||
onMounted(() => {
|
||||
userStore.initialize()
|
||||
|
||||
userStore.fetchUser()
|
||||
servicesStore.fetchServices()
|
||||
})
|
||||
</script>
|
||||
|
||||
|
@@ -1,3 +1,27 @@
|
||||
import { defineStore } from 'pinia'
|
||||
import { ref } from 'vue'
|
||||
|
||||
export const useServicesStore = defineStore('services', () => {})
|
||||
export const useServicesStore = defineStore('services', () => {
|
||||
const services = ref<Record<string, string>>({})
|
||||
|
||||
async function fetchServices() {
|
||||
try {
|
||||
const response = await fetch('/cgi/.well-known/services')
|
||||
if (!response.ok) {
|
||||
throw new Error('Network response was not ok')
|
||||
}
|
||||
const data = await response.json()
|
||||
services.value = data
|
||||
} catch (error) {
|
||||
console.error('Failed to fetch services:', error)
|
||||
services.value = {}
|
||||
}
|
||||
}
|
||||
|
||||
function getSerivceUrl(serviceName: string, ...parts: string[]): string | null {
|
||||
let baseUrl = services.value[serviceName] || null
|
||||
return baseUrl ? `${baseUrl}/${parts.join('/')}` : null
|
||||
}
|
||||
|
||||
return { services, fetchServices, getSerivceUrl }
|
||||
})
|
||||
|
@@ -43,8 +43,24 @@ export const useUserStore = defineStore('user', () => {
|
||||
// router.push('/login')
|
||||
}
|
||||
|
||||
async function initialize() {
|
||||
await fetchUser()
|
||||
function initialize() {
|
||||
const allowedOrigin = import.meta.env.DEV ? window.location.origin : 'https://id.solian.app'
|
||||
window.addEventListener('message', (event) => {
|
||||
// IMPORTANT: Always check the origin of the message for security!
|
||||
// This prevents malicious scripts from sending fake login status updates.
|
||||
// Ensure event.origin exactly matches your identity service's origin.
|
||||
if (event.origin !== allowedOrigin) {
|
||||
console.warn(`[SYNC] Message received from unexpected origin: ${event.origin}. Ignoring.`)
|
||||
return // Ignore messages from unknown origins
|
||||
}
|
||||
|
||||
// Check if the message is the type we're expecting
|
||||
if (event.data && event.data.type === 'DY:LOGIN_STATUS_CHANGE') {
|
||||
const { loggedIn } = event.data
|
||||
console.log(`[SYNC] Received login status change: ${loggedIn}`)
|
||||
fetchUser() // Re-fetch user data on login status change
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
return {
|
||||
|
@@ -1,10 +1,9 @@
|
||||
<template>
|
||||
<section class="h-full relative flex items-center justify-center">
|
||||
<n-card class="max-w-lg" title="About">
|
||||
<n-card class="max-w-lg" title="About" v-if="!userStore.user">
|
||||
<p>Welcome to the <b>Solar Drive</b></p>
|
||||
<p>
|
||||
We help you upload, collect, and share files with ease in mind.
|
||||
</p>
|
||||
<p>We help you upload, collect, and share files with ease in mind.</p>
|
||||
<p>To continue, login first.</p>
|
||||
|
||||
<p class="mt-4 opacity-75 text-xs">
|
||||
<span v-if="version == null">Loading...</span>
|
||||
@@ -15,12 +14,31 @@
|
||||
</span>
|
||||
</p>
|
||||
</n-card>
|
||||
<n-card class="max-w-2xl" v-else>
|
||||
<dashboard
|
||||
:uppy="uppy"
|
||||
:props="{ theme: 'auto', height: '28rem', proudlyDisplayPoweredByUppy: false }"
|
||||
/>
|
||||
</n-card>
|
||||
</section>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { useUserStore } from '@/stores/user'
|
||||
import { NCard } from 'naive-ui'
|
||||
import { onMounted, ref } from 'vue'
|
||||
import { Dashboard } from '@uppy/vue'
|
||||
|
||||
import Uppy from '@uppy/core'
|
||||
import Tus from '@uppy/tus'
|
||||
|
||||
import '@uppy/core/dist/style.min.css'
|
||||
import '@uppy/dashboard/dist/style.min.css'
|
||||
|
||||
const uppy = new Uppy()
|
||||
uppy.use(Tus, { endpoint: '/api/tus' })
|
||||
|
||||
const userStore = useUserStore()
|
||||
|
||||
const version = ref<any>(null)
|
||||
|
||||
|
Reference in New Issue
Block a user