2021-08-11 19:08:18 +00:00
|
|
|
<template>
|
|
|
|
<card :title="$t('user.deletion.title')" v-if="userDeletionEnabled">
|
|
|
|
<template v-if="deletionScheduledAt !== null">
|
|
|
|
<form @submit.prevent="cancelDeletion()">
|
|
|
|
<p>
|
|
|
|
{{
|
|
|
|
$t('user.deletion.scheduled', {
|
|
|
|
date: formatDateShort(deletionScheduledAt),
|
|
|
|
dateSince: formatDateSince(deletionScheduledAt),
|
|
|
|
})
|
|
|
|
}}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{{ $t('user.deletion.scheduledCancelText') }}
|
|
|
|
</p>
|
|
|
|
<div class="field">
|
|
|
|
<label class="label" for="currentPasswordAccountDelete">
|
|
|
|
{{ $t('user.settings.currentPassword') }}
|
|
|
|
</label>
|
|
|
|
<div class="control">
|
|
|
|
<input
|
|
|
|
class="input"
|
|
|
|
:class="{'is-danger': errPasswordRequired}"
|
|
|
|
id="currentPasswordAccountDelete"
|
|
|
|
:placeholder="$t('user.settings.currentPasswordPlaceholder')"
|
|
|
|
type="password"
|
|
|
|
v-model="password"
|
|
|
|
@keyup="() => errPasswordRequired = password === ''"
|
|
|
|
ref="passwordInput"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<p class="help is-danger" v-if="errPasswordRequired">
|
|
|
|
{{ $t('user.deletion.passwordRequired') }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<x-button
|
|
|
|
:loading="accountDeleteService.loading"
|
|
|
|
@click="cancelDeletion()"
|
|
|
|
class="is-fullwidth mt-4">
|
|
|
|
{{ $t('user.deletion.scheduledCancelConfirm') }}
|
|
|
|
</x-button>
|
|
|
|
</template>
|
|
|
|
<template v-else>
|
|
|
|
<form @submit.prevent="deleteAccount()">
|
|
|
|
<p>
|
|
|
|
{{ $t('user.deletion.text1') }}
|
|
|
|
</p>
|
|
|
|
<p>
|
|
|
|
{{ $t('user.deletion.text2') }}
|
|
|
|
</p>
|
|
|
|
<div class="field">
|
|
|
|
<label class="label" for="currentPasswordAccountDelete">
|
|
|
|
{{ $t('user.settings.currentPassword') }}
|
|
|
|
</label>
|
|
|
|
<div class="control">
|
|
|
|
<input
|
|
|
|
class="input"
|
|
|
|
:class="{'is-danger': errPasswordRequired}"
|
|
|
|
id="currentPasswordAccountDelete"
|
|
|
|
:placeholder="$t('user.settings.currentPasswordPlaceholder')"
|
|
|
|
type="password"
|
|
|
|
v-model="password"
|
|
|
|
@keyup="() => errPasswordRequired = password === ''"
|
|
|
|
ref="passwordInput"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<p class="help is-danger" v-if="errPasswordRequired">
|
|
|
|
{{ $t('user.deletion.passwordRequired') }}
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
|
|
|
|
<x-button
|
|
|
|
:loading="accountDeleteService.loading"
|
|
|
|
@click="deleteAccount()"
|
|
|
|
class="is-fullwidth mt-4 is-danger">
|
|
|
|
{{ $t('user.deletion.confirm') }}
|
|
|
|
</x-button>
|
|
|
|
</template>
|
|
|
|
</card>
|
|
|
|
</template>
|
|
|
|
|
2022-02-15 12:07:34 +00:00
|
|
|
<script lang="ts">
|
2022-06-23 01:08:35 +00:00
|
|
|
export default { name: 'user-settings-deletion' }
|
2022-05-14 14:45:45 +00:00
|
|
|
</script>
|
2021-08-11 19:08:18 +00:00
|
|
|
|
2022-05-14 14:45:45 +00:00
|
|
|
<script setup lang="ts">
|
|
|
|
import {ref, shallowReactive, computed} from 'vue'
|
2022-07-21 16:45:58 +00:00
|
|
|
import {useStore} from '@/store'
|
2022-05-14 14:45:45 +00:00
|
|
|
import {useI18n} from 'vue-i18n'
|
2021-10-11 17:37:20 +00:00
|
|
|
|
2022-05-14 14:45:45 +00:00
|
|
|
import AccountDeleteService from '@/services/accountDelete'
|
|
|
|
import {parseDateOrNull} from '@/helpers/parseDateOrNull'
|
2022-06-23 00:58:00 +00:00
|
|
|
import {formatDateShort, formatDateSince} from '@/helpers/time/formatDate'
|
2022-05-14 14:45:45 +00:00
|
|
|
import {useTitle} from '@/composables/useTitle'
|
|
|
|
import {success} from '@/message'
|
2021-08-11 19:08:18 +00:00
|
|
|
|
2022-05-23 05:23:59 +00:00
|
|
|
const {t} = useI18n({useScope: 'global'})
|
2022-05-14 14:45:45 +00:00
|
|
|
useTitle(() => `${t('user.deletion.title')} - ${t('user.settings.title')}`)
|
|
|
|
|
|
|
|
const accountDeleteService = shallowReactive(new AccountDeleteService())
|
|
|
|
const password = ref('')
|
|
|
|
const errPasswordRequired = ref(false)
|
|
|
|
|
|
|
|
const store = useStore()
|
|
|
|
const userDeletionEnabled = computed(() => store.state.config.userDeletionEnabled)
|
|
|
|
const deletionScheduledAt = computed(() => parseDateOrNull(store.state.auth.info?.deletionScheduledAt))
|
|
|
|
|
|
|
|
const passwordInput = ref()
|
|
|
|
async function deleteAccount() {
|
|
|
|
if (password.value === '') {
|
|
|
|
errPasswordRequired.value = true
|
|
|
|
passwordInput.value.focus()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await accountDeleteService.request(password.value)
|
|
|
|
success({message: t('user.deletion.requestSuccess')})
|
|
|
|
password.value = ''
|
|
|
|
}
|
|
|
|
|
|
|
|
async function cancelDeletion() {
|
|
|
|
if (password.value === '') {
|
|
|
|
errPasswordRequired.value = true
|
|
|
|
passwordInput.value.focus()
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
await accountDeleteService.cancel(password.value)
|
|
|
|
success({message: t('user.deletion.scheduledCancelSuccess')})
|
|
|
|
store.dispatch('auth/refreshUserInfo')
|
|
|
|
password.value = ''
|
|
|
|
}
|
2021-08-11 19:08:18 +00:00
|
|
|
</script>
|