Skip to content

Commit

Permalink
fix(AccountPassword): Add autocompletion
Browse files Browse the repository at this point in the history
  • Loading branch information
becem-gharbi committed Nov 7, 2023
1 parent b54e17e commit 8813556
Showing 1 changed file with 69 additions and 47 deletions.
116 changes: 69 additions & 47 deletions components/Account/Password.vue
Original file line number Diff line number Diff line change
@@ -1,65 +1,87 @@
<template>
<n-form ref="formRef" :model="model" :rules="rules" @submit.prevent="() => onSubmit(handleChangePassword)">
<n-form-item label="Current password" path="currentPassword">
<n-input v-model:value="model.currentPassword" type="password" show-password-on="click"></n-input>
</n-form-item>
<n-form
ref="formRef"
:model="model"
:rules="rules"
@submit.prevent="() => onSubmit(handleChangePassword)"
>
<n-form-item label="Current password" path="currentPassword">
<n-input
v-model:value="model.currentPassword"
type="password"
show-password-on="click"
:input-props="{ autocomplete: 'current-password' }"
></n-input>
</n-form-item>

<n-form-item label="New password" path="newPassword">
<n-input v-model:value="model.newPassword" type="password" show-password-on="click"></n-input>
</n-form-item>
<n-form-item label="New password" path="newPassword">
<n-input
v-model:value="model.newPassword"
type="password"
show-password-on="click"
:input-props="{ autocomplete: 'new-password' }"
></n-input>
</n-form-item>

<n-button attr-type="submit" :loading="pending" class="float-right" type="primary">
Change password
</n-button>
</n-form>
<n-button
attr-type="submit"
:loading="pending"
class="float-right"
type="primary"
>
Change password
</n-button>
</n-form>
</template>

<script setup lang="ts">
const { changePassword } = useAuth()
const { changePassword } = useAuth();
const message = useMessage()
const message = useMessage();
const { formRef, onSubmit, pending, rules, apiErrors } = useNaiveForm()
const { formRef, onSubmit, pending, rules, apiErrors } = useNaiveForm();
const model = ref({
currentPassword: "",
newPassword: ""
})
currentPassword: "",
newPassword: "",
});
apiErrors.value = {
wrongPassword: false
}
wrongPassword: false,
};
rules.value = {
currentPassword: [
{
required: true,
message: "Please enter your password",
trigger: "blur"
},
{
validator: () => !apiErrors.value.wrongPassword,
message: "Wrong password",
trigger: "input"
}
],
newPassword: [
{
required: true,
message: "Please enter your new password",
trigger: "input"
},
]
}
currentPassword: [
{
required: true,
message: "Please enter your password",
trigger: "blur",
},
{
validator: () => !apiErrors.value.wrongPassword,
message: "Wrong password",
trigger: "input",
},
],
newPassword: [
{
required: true,
message: "Please enter your new password",
trigger: "input",
},
],
};
async function handleChangePassword() {
await changePassword({
currentPassword: model.value.currentPassword,
newPassword: model.value.newPassword
}).then(() => {
message.success("Your password is changed")
}).catch((e) => {
apiErrors.value.wrongPassword = e.data.message === "wrong-password"
await changePassword({
currentPassword: model.value.currentPassword,
newPassword: model.value.newPassword,
})
.then(() => {
message.success("Your password is changed");
})
.catch((e) => {
apiErrors.value.wrongPassword = e.data.message === "wrong-password";
});
}
</script>
</script>

0 comments on commit 8813556

Please sign in to comment.