delete account ui functionality

This commit is contained in:
2023-05-28 23:21:59 +02:00
parent b3f740770a
commit 06bfd4cd9e
6 changed files with 63 additions and 30 deletions

View File

@@ -33,6 +33,7 @@ provide('firebaseAuthUI', firebaseAuthUI)
watch( watch(
[activeNotesSource, encryptionKey], [activeNotesSource, encryptionKey],
() => { () => {
console.log(activeNotesSource.value)
if (activeNotesSource.value === 'firebase') { if (activeNotesSource.value === 'firebase') {
getClientKey() getClientKey()
getEncryptionKey() getEncryptionKey()
@@ -51,7 +52,7 @@ const submitPassphrase = (close: () => void) => {
if (passphraseValid.value) close() if (passphraseValid.value) close()
} }
const loading = computed(() => notes.value.length === 0 || passphraseRequired.value) const loading = computed(() => notes.value.length === 0 || passphraseRequired.value || !activeNotesSource.value)
provide('loading', loading) provide('loading', loading)
</script> </script>
@@ -100,14 +101,14 @@ provide('loading', loading)
<UIModal :open="passphraseRequired" :persistent="true"> <UIModal :open="passphraseRequired" :persistent="true">
<template #title>Enter your passphrase</template> <template #title>Enter your passphrase</template>
<template #default="{ close }"> <template #default="{ close }">
<p> <div>
Your notes are encrypted. Please enter your encryption key passphrase to decrypt your cloud Your notes are encrypted. Please enter your encryption key passphrase to decrypt your cloud
notes. notes.
</p> </div>
<form @submit.prevent="submitPassphrase(close)"> <form @submit.prevent="submitPassphrase(close)">
<UIInputText <UIInputText
type="password" type="password"
class="w-full max-w-full" class="w-full !max-w-full"
:color="passphraseValid === false ? 'error' : 'regular'" :color="passphraseValid === false ? 'error' : 'regular'"
v-model="passphrase" v-model="passphrase"
></UIInputText> ></UIInputText>

View File

@@ -23,6 +23,11 @@ const exportNotes = async () => {
FileSaver.saveAs(blob, `contexted-${user.value?.email}-${currentDate}.zip`) FileSaver.saveAs(blob, `contexted-${user.value?.email}-${currentDate}.zip`)
} }
const showDeleteAccountDialog = ref(false)
const deleteAccount = () => {
console.log('delete account')
}
const showEncryptionDialog = ref(false) const showEncryptionDialog = ref(false)
watch(showEncryptionDialog, () => { watch(showEncryptionDialog, () => {
passphrase.value = '' passphrase.value = ''
@@ -104,16 +109,37 @@ const toggleEncryption = async () => {
Export notes Export notes
</UIButton> </UIButton>
</div> </div>
<div class="items-top w-full flex-row sm:flex"> <div class="items-top w-full flex-row sm:flex sm:flex-grow">
<div class="font-bold sm:w-4/12">Delete account</div> <div class="flex-shrink-0 font-bold sm:w-4/12">Delete account</div>
<UIButton size="sm" color="error"> <div>
<i class="fa-fw fa-solid fa-trash mr-2"></i> <UIButton size="sm" color="error" @click="showDeleteAccountDialog = true">
Delete account <i class="fa-fw fa-solid fa-trash mr-2"></i>
</UIButton> Delete account
</UIButton>
<UIAlert
color="warning"
density="compact"
class="mt-1 space-y-2"
v-if="showDeleteAccountDialog"
>
<div>
Are you sure you want to delete your Contexted account? This action cannot be
undone!
</div>
<div class="space-x-2">
<UIButton size="sm" variant="outline" color="primary" @click="deleteAccount">
Delete account
</UIButton>
<UIButton size="sm" variant="outline" @click="showDeleteAccountDialog = false">
Close
</UIButton>
</div>
</UIAlert>
</div>
</div> </div>
<div class="items-top w-full flex-row sm:flex"> <div class="items-top w-full flex-row sm:flex">
<div class="font-bold sm:w-4/12">End-to-end encryption</div> <div class="flex-shrink-0 font-bold sm:w-4/12">End-to-end encryption</div>
<div> <div class="w-full">
<template v-if="!encryptionEnabled"> <template v-if="!encryptionEnabled">
<UIButton <UIButton
size="sm" size="sm"
@@ -135,7 +161,7 @@ const toggleEncryption = async () => {
</UIButton> </UIButton>
</template> </template>
<UIAlert color="info" density="compact" v-if="showEncryptionDialog"> <UIAlert color="info" density="compact" v-if="showEncryptionDialog">
<div class="space-y-2"> <div class="w-full space-y-2">
<div> <div>
Enter your passphrase to Enter your passphrase to
{{ encryptionEnabled ? 'disable' : 'enable' }} {{ encryptionEnabled ? 'disable' : 'enable' }}
@@ -146,22 +172,25 @@ const toggleEncryption = async () => {
type="password" type="password"
:color="toggleEncryptionError ? 'error' : 'regular'" :color="toggleEncryptionError ? 'error' : 'regular'"
v-model="passphrase" v-model="passphrase"
class="w-full" class="w-full !max-w-full"
/> />
<UIAlert density="compact" color="error" v-if="toggleEncryptionError"> <UIAlert density="compact" color="error" v-if="toggleEncryptionError">
<i class="fa-solid fa-triangle-exclamation"></i> <i class="fa-solid fa-triangle-exclamation"></i>
{{ toggleEncryptionError }} {{ toggleEncryptionError }}
</UIAlert> </UIAlert>
<div class="flex justify-end space-x-2"> <div class="space-x-2">
<UIButton size="sm" @click="showEncryptionDialog = false">Close</UIButton>
<UIButton <UIButton
:disabled="passphrase.length === 0" :disabled="passphrase.length === 0"
size="sm" size="sm"
variant="outline"
color="primary" color="primary"
@click="toggleEncryption" @click="toggleEncryption"
> >
{{ encryptionEnabled ? 'Disable' : 'Enable' }} encryption {{ encryptionEnabled ? 'Disable' : 'Enable' }} encryption
</UIButton> </UIButton>
<UIButton size="sm" variant="outline" @click="showEncryptionDialog = false">
Close
</UIButton>
</div> </div>
</div> </div>
</UIAlert> </UIAlert>

View File

@@ -10,14 +10,14 @@ const props = withDefaults(defineProps<Props>(), {
const styleClass = computed(() => { const styleClass = computed(() => {
const colorVariants = { const colorVariants = {
'info': 'dui-alert-info', info: 'bg-info',
'success': 'dui-alert-success', success: 'bg-success',
'warning': 'dui-alert-warning', warning: 'bg-warning',
'error': 'dui-alert-error' error: 'bg-error'
} }
const densityVariants = { const densityVariants = {
'regular': 'py-4 px-4', regular: 'py-4 px-4',
'compact': 'py-2 px-4' compact: 'py-2 px-4'
} }
const colorClass = colorVariants[props.color] const colorClass = colorVariants[props.color]
const densityClass = densityVariants[props.density] const densityClass = densityVariants[props.density]
@@ -25,7 +25,7 @@ const styleClass = computed(() => {
}) })
</script> </script>
<template> <template>
<div class="dui-alert shadow-lg items-start" :class="styleClass"> <div class="rounded-xl shadow-lg" :class="styleClass">
<div class="flex items-center w-full"><slot></slot></div> <slot></slot>
</div> </div>
</template> </template>

View File

@@ -67,13 +67,13 @@ defineExpose({ open, close })
<Transition @enter="onEnter" @leave="onLeave" appear> <Transition @enter="onEnter" @leave="onLeave" appear>
<div class="dui-modal bg-neutral-800 bg-opacity-60" v-if="show" ref="modal"> <div class="dui-modal bg-neutral-800 bg-opacity-60" v-if="show" ref="modal">
<div class="dui-modal-box" :class="styleClass" ref="modalBox"> <div class="dui-modal-box" :class="styleClass" ref="modalBox">
<h3 class="flex items-center text-xl font-bold" v-if="$slots.title"> <h3 class="flex items-center text-xl font-bold mb-4" v-if="$slots.title">
<slot name="title" /> <slot name="title" />
</h3> </h3>
<p class="py-4"> <div>
<slot v-bind="slotProps" /> <slot v-bind="slotProps" />
</p> </div>
<div class="dui-modal-action"> <div class="dui-modal-action mt-4">
<slot name="actions" v-bind="slotProps"> <slot name="actions" v-bind="slotProps">
<UIButton size="sm" @click="close">Close</UIButton> <UIButton size="sm" @click="close">Close</UIButton>
</slot> </slot>

View File

@@ -69,10 +69,12 @@ export const encryptionKey = ref<EncryptionKey | null>()
export async function getEncryptionKey() { export async function getEncryptionKey() {
encryptedEncryptionKey.value = (await getEncryptedEncryptionKey()) || undefined encryptedEncryptionKey.value = (await getEncryptedEncryptionKey()) || undefined
if (!encryptedEncryptionKey.value || !clientKey.value) { if (encryptedEncryptionKey.value && clientKey.value) {
encryptionKey.value = decrypt(encryptedEncryptionKey.value, clientKey.value)
} else if (!encryptedEncryptionKey.value) {
encryptionKey.value = null encryptionKey.value = null
} else { } else {
encryptionKey.value = decrypt(encryptedEncryptionKey.value, clientKey.value) encryptionKey.value = undefined
} }
} }

View File

@@ -263,6 +263,7 @@ export const getNotes = async () => {
if (encryptionKey.value === undefined || !user.value || !db.value) return if (encryptionKey.value === undefined || !user.value || !db.value) return
const firebaseNotes = (await getDoc(doc(db.value, 'pages', user.value.uid))).data() as BaseNotes const firebaseNotes = (await getDoc(doc(db.value, 'pages', user.value.uid))).data() as BaseNotes
notes = encryptionKey.value ? decryptNotes(firebaseNotes, encryptionKey.value) : firebaseNotes notes = encryptionKey.value ? decryptNotes(firebaseNotes, encryptionKey.value) : firebaseNotes
console.log(encryptionKey.value)
console.log('get notes from firebase', notes) console.log('get notes from firebase', notes)
} }
baseNotes.value = parseBaseNotes(notes) baseNotes.value = parseBaseNotes(notes)