2022-09-26 16:23:45 +02:00
|
|
|
<template>
|
2023-03-20 11:23:46 +01:00
|
|
|
<div class="flex flex-col gap-5 mx-auto p-2 w-full max-w-md">
|
|
|
|
<form @submit.prevent="savePassword" class="flex flex-col">
|
|
|
|
<label class="font-bold">Oud Wachtwoord</label>
|
|
|
|
<input v-model="form.oldPassword" required="true" class="input mb-5" :type="showPassword ? 'text' : 'password'">
|
|
|
|
|
|
|
|
<label class="font-bold">Nieuw Wachtwoord</label>
|
|
|
|
<input v-model="form.newPassword" required="true" class="input mb-5" :type="showPassword ? 'text' : 'password'">
|
|
|
|
|
|
|
|
<label class="font-bold">Herhaal Nieuw Wachtwoord</label>
|
|
|
|
<input v-model="form.confirmNewPassword" required="true" class="input" :type="showPassword ? 'text' : 'password'">
|
|
|
|
|
|
|
|
<div class="mb-5 mt-1 flex items-center text-default">
|
|
|
|
<input v-model="showPassword" type="checkbox" class="mr-1 checkbox ">
|
|
|
|
<span>Toon Wachtwoord</span>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="w-full flex flex-wrap justify-between">
|
|
|
|
<input :disabled="disableButtons" type="submit" value="Wijzig Wachtwoord" class="btn w-full sm:w-52 mb-1">
|
|
|
|
<button @click="router.back()" class="hover:underline font-bold w-full sm:w-max sm:ml-auto">Annuleer</button>
|
|
|
|
</div>
|
|
|
|
</form>
|
|
|
|
</div>
|
2022-09-26 16:23:45 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup>
|
2022-09-26 16:59:49 +02:00
|
|
|
import { reauthenticateWithCredential, EmailAuthProvider, updatePassword } from 'firebase/auth'
|
|
|
|
import { useToast } from 'vue-toastification'
|
|
|
|
|
2022-09-26 16:23:45 +02:00
|
|
|
definePageMeta({
|
2023-03-20 11:23:46 +01:00
|
|
|
title: 'Wachtwoord Wijzigen',
|
|
|
|
key: 'back'
|
2022-09-26 16:23:45 +02:00
|
|
|
})
|
2022-09-26 16:59:49 +02:00
|
|
|
|
|
|
|
const toast = useToast()
|
|
|
|
const router = useRouter()
|
2023-03-20 11:23:46 +01:00
|
|
|
const userStore = useUserStore()
|
2022-09-26 16:59:49 +02:00
|
|
|
|
|
|
|
const form = ref({
|
2023-03-20 11:23:46 +01:00
|
|
|
oldPassword: '',
|
|
|
|
newPassword: '',
|
|
|
|
confirmNewPassword: '',
|
2022-09-26 16:59:49 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
onMounted(() => {
|
2023-03-20 11:23:46 +01:00
|
|
|
form.value = {
|
|
|
|
oldPassword: '',
|
|
|
|
newPassword: '',
|
|
|
|
confirmNewPassword: '',
|
|
|
|
}
|
2022-09-26 16:59:49 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
const savePassword = () => {
|
2023-03-20 11:23:46 +01:00
|
|
|
if (form.value.newPassword !== form.value.confirmNewPassword) return alert ('Niewe wachtwoorden zijn niet hetzelfde')
|
|
|
|
|
|
|
|
disableButtons.value = true
|
2022-09-26 16:59:49 +02:00
|
|
|
|
2023-03-20 11:23:46 +01:00
|
|
|
const credential = EmailAuthProvider.credential(
|
|
|
|
userStore.user.email,
|
|
|
|
form.value.oldPassword
|
|
|
|
)
|
2022-09-26 16:59:49 +02:00
|
|
|
|
2023-03-20 11:23:46 +01:00
|
|
|
reauthenticateWithCredential(userStore.auth.currentUser, credential).then(() => {
|
|
|
|
updatePassword(userStore.auth.currentUser, form.value.newPassword).then(() => {
|
|
|
|
toast.success('Wachtwoord is veranderd')
|
2022-09-26 16:59:49 +02:00
|
|
|
|
2023-03-20 11:23:46 +01:00
|
|
|
navigateTo('/settings')
|
|
|
|
disableButtons.value = false
|
|
|
|
}).catch((error) => {
|
|
|
|
toast.error('Error tijdens het wachtwoord veranderen')
|
|
|
|
console.log(error)
|
|
|
|
disableButtons.value = false
|
2022-09-26 16:59:49 +02:00
|
|
|
});
|
2023-03-20 11:23:46 +01:00
|
|
|
}).catch((error) => {
|
|
|
|
disableButtons.value = false
|
|
|
|
|
|
|
|
if (error.code === 'auth/wrong-password') return toast.error('Oude wachtwoord is onjuist')
|
|
|
|
|
|
|
|
toast.error('Error tijdens het wachtwoord veranderen')
|
2022-09-26 16:59:49 +02:00
|
|
|
|
2023-03-20 11:23:46 +01:00
|
|
|
console.log(error)
|
|
|
|
});
|
2022-09-26 16:59:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
const showPassword = ref(false)
|
|
|
|
const disableButtons = ref(false)
|
2023-01-22 15:12:15 +01:00
|
|
|
</script>
|