Create change password with and without token and add related features
gitea/hedera-web/pipeline/pr-4922-vueMigration This commit looks good Details

This commit is contained in:
William Buezas 2024-07-26 09:09:21 -03:00
parent 06cd9b01d3
commit ef36566442
1 changed files with 30 additions and 2 deletions

View File

@ -1,5 +1,5 @@
<script setup> <script setup>
import { ref, inject, onMounted } from 'vue'; import { ref, inject, onMounted, nextTick } from 'vue';
import { useI18n } from 'vue-i18n'; import { useI18n } from 'vue-i18n';
import { useRouter } from 'vue-router'; import { useRouter } from 'vue-router';
@ -15,6 +15,8 @@ const userStore = useUserStore();
const { notify } = useNotify(); const { notify } = useNotify();
const router = useRouter(); const router = useRouter();
const oldPasswordRef = ref(null);
const newPasswordRef = ref(null);
const passwordRequirementsDialogRef = ref(null); const passwordRequirementsDialogRef = ref(null);
const vnFormRef = ref(null); const vnFormRef = ref(null);
const repeatPassword = ref(''); const repeatPassword = ref('');
@ -35,6 +37,21 @@ const changePassword = async () => {
notify(t('passwordsDoNotMatch'), 'negative'); notify(t('passwordsDoNotMatch'), 'negative');
throw new Error('Passwords do not match'); throw new Error('Passwords do not match');
} }
if (userStore.token) {
await changePasswordWithToken(userStore.token);
} else {
await changePasswordWithoutToken();
}
};
const changePasswordWithToken = async token => {
const headers = {
Authorization: token
};
await api.post('VnUsers/reset-password', formData.value, { headers });
};
const changePasswordWithoutToken = async () => {
await api.patch('Accounts/change-password', formData.value); await api.patch('Accounts/change-password', formData.value);
}; };
@ -52,7 +69,15 @@ const logout = async () => {
router.push({ name: 'Login' }); router.push({ name: 'Login' });
}; };
onMounted(async () => await getPasswordRequirements()); onMounted(async () => {
getPasswordRequirements();
await nextTick();
if (userStore.token) {
newPasswordRef.value.focus();
} else {
oldPasswordRef.value.focus();
}
});
</script> </script>
<template> <template>
@ -68,11 +93,14 @@ onMounted(async () => await getPasswordRequirements());
> >
<template #form> <template #form>
<VnInput <VnInput
v-if="!userStore.token"
ref="oldPasswordRef"
v-model="formData.oldPassword" v-model="formData.oldPassword"
:label="t('oldPassword')" :label="t('oldPassword')"
type="password" type="password"
/> />
<VnInput <VnInput
ref="newPasswordRef"
v-model="formData.newPassword" v-model="formData.newPassword"
:label="t('newPassword')" :label="t('newPassword')"
type="password" type="password"