86 lines
2.1 KiB
Vue
86 lines
2.1 KiB
Vue
|
|
<script setup>
|
||
|
|
|
||
|
|
import { ref, useTemplateRef, computed } from 'vue';
|
||
|
|
import { PasswordInput, Dialog, FormGroup } from 'pankow';
|
||
|
|
import ProfileModel from '../../models/ProfileModel.js';
|
||
|
|
|
||
|
|
const emit = defineEmits([ 'success' ]);
|
||
|
|
|
||
|
|
const profileModel = ProfileModel.create();
|
||
|
|
|
||
|
|
const dialog = useTemplateRef('dialog');
|
||
|
|
const formError = ref({});
|
||
|
|
const busy = ref (false);
|
||
|
|
const password = ref('');
|
||
|
|
|
||
|
|
const isFormValid = computed(() => {
|
||
|
|
if (!password.value) return false;
|
||
|
|
|
||
|
|
return true;
|
||
|
|
});
|
||
|
|
|
||
|
|
async function onSubmit() {
|
||
|
|
if (!isFormValid.value) return;
|
||
|
|
|
||
|
|
busy.value = true;
|
||
|
|
formError.value = {};
|
||
|
|
|
||
|
|
const [error] = await profileModel.disableTwoFA(password.value);
|
||
|
|
if (error) {
|
||
|
|
if (error.status === 412) formError.value.password = error.body.message;
|
||
|
|
else {
|
||
|
|
formError.value.generic = error.status ? error.body.message : 'Internal error';
|
||
|
|
console.error('Failed to disable 2fa', error);
|
||
|
|
}
|
||
|
|
|
||
|
|
busy.value = false;
|
||
|
|
|
||
|
|
return;
|
||
|
|
}
|
||
|
|
|
||
|
|
emit('success');
|
||
|
|
dialog.value.close();
|
||
|
|
|
||
|
|
busy.value = false;
|
||
|
|
formError.value = {};
|
||
|
|
}
|
||
|
|
|
||
|
|
defineExpose({
|
||
|
|
async open() {
|
||
|
|
password.value = '';
|
||
|
|
busy.value = false;
|
||
|
|
formError.value = {};
|
||
|
|
dialog.value.open();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
</script>
|
||
|
|
|
||
|
|
<template>
|
||
|
|
<Dialog ref="dialog"
|
||
|
|
:title="$t('profile.disable2FA.title')"
|
||
|
|
:confirm-label="$t('profile.disable2FA.disable')"
|
||
|
|
:confirm-active="!busy && isFormValid"
|
||
|
|
:confirm-busy="busy"
|
||
|
|
confirm-style="primary"
|
||
|
|
:reject-label="$t('main.dialog.cancel')"
|
||
|
|
:reject-active="!busy"
|
||
|
|
reject-style="secondary"
|
||
|
|
@confirm="onSubmit"
|
||
|
|
>
|
||
|
|
<form @submit.prevent="onSubmit">
|
||
|
|
<fieldset :disabled="busy">
|
||
|
|
<input type="submit" style="display: none;" :disabled="!isFormValid"/>
|
||
|
|
|
||
|
|
<div class="error-label" v-if="formError.generic">{{ formError.generic }}</div>
|
||
|
|
|
||
|
|
<FormGroup :has-error="formError.password">
|
||
|
|
<label>{{ $t('profile.disable2FA.password') }}</label>
|
||
|
|
<PasswordInput v-model="password" />
|
||
|
|
<div class="error-label" v-if="formError.password">{{ formError.password }}</div>
|
||
|
|
</FormGroup>
|
||
|
|
</fieldset>
|
||
|
|
</form>
|
||
|
|
</Dialog>
|
||
|
|
</template>
|