mirror of
https://github.com/jwinterm/modoboa.git
synced 2026-12-05 12:34:08 +01:00
Use validation rule in password form
This commit is contained in:
@@ -1,14 +1,15 @@
|
||||
<template>
|
||||
<div>
|
||||
<template v-if="withPasswordCheck">
|
||||
<label class="m-label">{{ $gettext('Current password') }}</label>
|
||||
<label class="m-label">{{ $gettext("Current password") }}</label>
|
||||
<v-text-field
|
||||
v-model="account.currentPassword"
|
||||
autocomplete="new-password"
|
||||
variant="outlined"
|
||||
type="password"
|
||||
density="compact"
|
||||
validate-on="submit"
|
||||
:rules="disabled ? [] : [rules.required]"
|
||||
:rules="disabled ? [] : [rules.required, validPassword]"
|
||||
:disabled="disabled"
|
||||
/>
|
||||
</template>
|
||||
@@ -73,58 +74,58 @@
|
||||
</template>
|
||||
|
||||
<script setup lang="js">
|
||||
import { useBusStore } from '@/stores'
|
||||
import accountsApi from '@/api/accounts'
|
||||
import accountApi from '@/api/account'
|
||||
import { computed } from 'vue'
|
||||
import rules from '@/plugins/rules'
|
||||
import { useGettext } from 'vue3-gettext'
|
||||
import { useBusStore } from "@/stores";
|
||||
import accountsApi from "@/api/accounts";
|
||||
import accountApi from "@/api/account";
|
||||
import { computed } from "vue";
|
||||
import rules from "@/plugins/rules";
|
||||
import { useGettext } from "vue3-gettext";
|
||||
|
||||
const { $gettext } = useGettext()
|
||||
const busStore = useBusStore()
|
||||
const { $gettext } = useGettext();
|
||||
const busStore = useBusStore();
|
||||
const props = defineProps({
|
||||
modelValue: { type: Object, default: null },
|
||||
withPasswordCheck: { type: Boolean, default: false },
|
||||
disabled: { type: Boolean, default: false },
|
||||
editing: { type: Boolean, default: false },
|
||||
formErrors: { type: Object, required: false, default: () => {} },
|
||||
})
|
||||
});
|
||||
|
||||
const account = computed(() => props.modelValue)
|
||||
const account = computed(() => props.modelValue);
|
||||
|
||||
const isRuleActive = computed(
|
||||
() => !props.disabled && (!props.editing || account.value.password)
|
||||
)
|
||||
() => !props.disabled && (!props.editing || account.value.password),
|
||||
);
|
||||
|
||||
const passwordConfirmationRules = (value) =>
|
||||
value === account.value.password || $gettext('Password mismatch')
|
||||
value === account.value.password || $gettext("Password mismatch");
|
||||
|
||||
function copyPassword() {
|
||||
navigator.clipboard.writeText(account.value.password).then(() => {
|
||||
busStore.displayNotification({
|
||||
msg: $gettext('Password copied to clipboard'),
|
||||
})
|
||||
})
|
||||
msg: $gettext("Password copied to clipboard"),
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function updatePassword(value) {
|
||||
if (value) {
|
||||
accountsApi.getRandomPassword().then((resp) => {
|
||||
account.value.password = resp.data.password
|
||||
})
|
||||
account.value.password = resp.data.password;
|
||||
});
|
||||
} else {
|
||||
account.value.password = null
|
||||
account.value.password_confirmation = null
|
||||
account.value.password = null;
|
||||
account.value.password_confirmation = null;
|
||||
}
|
||||
}
|
||||
|
||||
async function validPassword() {
|
||||
if (account.value.password) {
|
||||
async function validPassword(value) {
|
||||
if (value) {
|
||||
return accountApi
|
||||
.checkPassword(account.value.password)
|
||||
.checkPassword(value)
|
||||
.then(() => true)
|
||||
.catch(() => $gettext('Invalid password'))
|
||||
.catch(() => $gettext("Invalid password"));
|
||||
}
|
||||
return true
|
||||
return true;
|
||||
}
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user