This commit is contained in:
parent
4bf8e1224d
commit
98cdeabe9f
|
@ -0,0 +1,112 @@
|
|||
<script setup>
|
||||
import { ref } from 'vue';
|
||||
import { useI18n } from 'vue-i18n';
|
||||
import VnRow from '../ui/VnRow.vue';
|
||||
import VnInput from './VnInput.vue';
|
||||
import FetchData from '../FetchData.vue';
|
||||
import useNotify from 'src/composables/useNotify';
|
||||
|
||||
const props = defineProps({ submitFn: { type: Function, default: () => {} } });
|
||||
|
||||
const { t } = useI18n();
|
||||
const { notify } = useNotify();
|
||||
|
||||
const form = ref();
|
||||
const changePassDialog = ref();
|
||||
const passwords = ref({ newPassword: null, repeatPassword: null });
|
||||
const requirements = ref([]);
|
||||
|
||||
const validate = async () => {
|
||||
const { newPassword, repeatPassword } = passwords.value;
|
||||
if (newPassword !== repeatPassword) {
|
||||
notify(t("Passwords don't match"), 'negative');
|
||||
return;
|
||||
}
|
||||
try {
|
||||
await props.submitFn(newPassword);
|
||||
} catch (e) {
|
||||
notify('errors.writeRequest', 'negative');
|
||||
} finally {
|
||||
changePassDialog.value.hide();
|
||||
}
|
||||
};
|
||||
|
||||
defineExpose({ show: () => changePassDialog.value.show() });
|
||||
</script>
|
||||
<template>
|
||||
<FetchData
|
||||
url="UserPasswords/findOne"
|
||||
auto-load
|
||||
@on-fetch="(data) => (requirements = data)"
|
||||
/>
|
||||
<QDialog ref="changePassDialog">
|
||||
<QCard style="width: 350px">
|
||||
<QCardSection>
|
||||
<slot name="header">
|
||||
<VnRow class="items-center" style="flex-direction: row">
|
||||
<span class="text-h6" v-text="t('Change password')" />
|
||||
<QIcon
|
||||
class="cursor-pointer"
|
||||
name="close"
|
||||
size="xs"
|
||||
style="flex: 0"
|
||||
v-close-popup
|
||||
/>
|
||||
</VnRow>
|
||||
</slot>
|
||||
</QCardSection>
|
||||
<QForm ref="form">
|
||||
<QCardSection>
|
||||
<VnInput
|
||||
:label="t('New password')"
|
||||
v-model="passwords.newPassword"
|
||||
type="password"
|
||||
:required="true"
|
||||
:info="
|
||||
t('passwordRequirements', {
|
||||
length: requirements.length,
|
||||
nAlpha: requirements.nAlpha,
|
||||
nUpper: requirements.nUpper,
|
||||
nDigits: requirements.nDigits,
|
||||
nPunct: requirements.nPunct,
|
||||
})
|
||||
"
|
||||
autofocus
|
||||
/>
|
||||
|
||||
<VnInput
|
||||
:label="t('Repeat password')"
|
||||
v-model="passwords.repeatPassword"
|
||||
type="password"
|
||||
/>
|
||||
</QCardSection>
|
||||
</QForm>
|
||||
<QCardActions>
|
||||
<slot name="actions">
|
||||
<QBtn
|
||||
:label="t('globals.cancel')"
|
||||
class="q-ml-sm"
|
||||
color="primary"
|
||||
flat
|
||||
type="reset"
|
||||
v-close-popup
|
||||
/>
|
||||
<QBtn
|
||||
:label="t('globals.confirm')"
|
||||
color="primary"
|
||||
@click="validate"
|
||||
/>
|
||||
</slot>
|
||||
</QCardActions>
|
||||
</QCard>
|
||||
</QDialog>
|
||||
</template>
|
||||
|
||||
<i18n>
|
||||
es:
|
||||
Change password: Cambiar contraseña
|
||||
New password: Nueva contraseña
|
||||
Repeat password: Repetir contraseña
|
||||
You must enter a new password: Debes introducir la nueva contraseña
|
||||
Passwords don't match: Las contraseñas no coinciden
|
||||
</i18n>
|
|
@ -3,14 +3,11 @@ import { computed, ref } from 'vue';
|
|||
import { useI18n } from 'vue-i18n';
|
||||
import { useRoute } from 'vue-router';
|
||||
import axios from 'axios';
|
||||
import { useQuasar } from 'quasar';
|
||||
|
||||
import VnInput from 'src/components/common/VnInput.vue';
|
||||
import CustomerChangePassword from 'src/pages/Customer/components/CustomerChangePassword.vue';
|
||||
import FormModel from 'components/FormModel.vue';
|
||||
import VnChangePassword from 'src/components/common/VnChangePassword.vue';
|
||||
|
||||
const { t } = useI18n();
|
||||
const quasar = useQuasar();
|
||||
const route = useRoute();
|
||||
const canChangePassword = ref(0);
|
||||
|
||||
|
@ -21,21 +18,11 @@ const filter = computed(() => {
|
|||
};
|
||||
});
|
||||
|
||||
const showChangePasswordDialog = () => {
|
||||
quasar.dialog({
|
||||
component: CustomerChangePassword,
|
||||
componentProps: {
|
||||
id: route.params.id,
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
async function hasCustomerRole() {
|
||||
const { data } = await axios(`Clients/${route.params.id}/hasCustomerRole`);
|
||||
canChangePassword.value = data;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<FormModel
|
||||
url="VnUsers/preview"
|
||||
|
@ -73,12 +60,21 @@ async function hasCustomerRole() {
|
|||
color="primary"
|
||||
icon="edit"
|
||||
:disable="!canChangePassword"
|
||||
@click="showChangePasswordDialog()"
|
||||
@click="$refs.changePassRef.show"
|
||||
/>
|
||||
</template>
|
||||
</FormModel>
|
||||
<VnChangePassword
|
||||
ref="changePassRef"
|
||||
:submit-fn="
|
||||
async (newPass) => {
|
||||
await axios.patch(`Clients/${$route.params.id}/setPassword`, {
|
||||
newPassword: newPass,
|
||||
});
|
||||
}
|
||||
"
|
||||
/>
|
||||
</template>
|
||||
|
||||
<i18n>
|
||||
es:
|
||||
Enable web access: Habilitar acceso web
|
||||
|
|
Loading…
Reference in New Issue