62f550c373
Selbstgehostete Web-Cloud mit Dateiverwaltung, Kalender, Kontakte, Email-Webclient, Office-Viewer und Passwort-Manager. Backend (Flask/Python): - JWT-Auth mit Access/Refresh Tokens, Benutzerverwaltung - Dateien: Upload/Download, Ordner, Berechtigungen, Share-Links - Kalender: CRUD, Teilen, iCal-Export, CalDAV well-known URLs - Kontakte: Adressbuecher, vCard-Export, Teilen - Email: IMAP/SMTP-Proxy, Multi-Account - Office-Viewer: DOCX/XLSX/PPTX/PDF Vorschau - Passwort-Manager: AES-256-GCM clientseitig, KeePass-Import - Sync-API fuer Desktop/Mobile-Clients - SQLite mit WAL-Modus Frontend (Vue 3 + PrimeVue): - Datei-Explorer mit Breadcrumbs und Share-Dialogen - Monatskalender mit Event-Verwaltung - Kontaktliste mit Adressbuch-Sidebar - Email-Client mit 3-Spalten-Layout - Passwort-Manager mit TOTP und Passwort-Generator - Admin-Panel, Settings, oeffentliche Share-Seite Docker: Multi-Stage Build, Bind Mounts (keine Volumes) Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
73 lines
2.0 KiB
JavaScript
73 lines
2.0 KiB
JavaScript
import { defineStore } from 'pinia'
|
|
import { ref, computed } from 'vue'
|
|
import apiClient from '../api/client'
|
|
|
|
export const useAuthStore = defineStore('auth', () => {
|
|
const user = ref(null)
|
|
const accessToken = ref(null)
|
|
const masterKeySalt = ref(null)
|
|
|
|
const isAuthenticated = computed(() => !!accessToken.value)
|
|
const isAdmin = computed(() => user.value?.role === 'admin')
|
|
const hasEmailAccounts = computed(() => (user.value?.email_account_count || 0) > 0)
|
|
|
|
async function login(username, password) {
|
|
const response = await apiClient.post('/auth/login', { username, password })
|
|
user.value = response.data.user
|
|
accessToken.value = response.data.access_token
|
|
masterKeySalt.value = response.data.master_key_salt
|
|
return response.data
|
|
}
|
|
|
|
async function register(username, password, email) {
|
|
const payload = { username, password }
|
|
if (email) payload.email = email
|
|
const response = await apiClient.post('/auth/register', payload)
|
|
user.value = response.data.user
|
|
accessToken.value = response.data.access_token
|
|
return response.data
|
|
}
|
|
|
|
async function refreshToken() {
|
|
const response = await apiClient.post('/auth/refresh')
|
|
accessToken.value = response.data.access_token
|
|
return response.data.access_token
|
|
}
|
|
|
|
async function fetchMe() {
|
|
const response = await apiClient.get('/auth/me')
|
|
user.value = response.data
|
|
masterKeySalt.value = response.data.master_key_salt
|
|
return response.data
|
|
}
|
|
|
|
async function changePassword(currentPassword, newPassword) {
|
|
await apiClient.post('/auth/change-password', {
|
|
current_password: currentPassword,
|
|
new_password: newPassword,
|
|
})
|
|
}
|
|
|
|
function logout() {
|
|
apiClient.post('/auth/logout').catch(() => {})
|
|
user.value = null
|
|
accessToken.value = null
|
|
masterKeySalt.value = null
|
|
}
|
|
|
|
return {
|
|
user,
|
|
accessToken,
|
|
masterKeySalt,
|
|
isAuthenticated,
|
|
isAdmin,
|
|
hasEmailAccounts,
|
|
login,
|
|
register,
|
|
refreshToken,
|
|
fetchMe,
|
|
changePassword,
|
|
logout,
|
|
}
|
|
})
|