-
Notifications
You must be signed in to change notification settings - Fork 847
/
Copy pathUpdatePasswordForm.vue
100 lines (89 loc) · 3.33 KB
/
UpdatePasswordForm.vue
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
<script setup>
import { ref } from 'vue';
import { useForm } from '@inertiajs/inertia-vue3';
import JetActionMessage from '@/Components/ActionMessage.vue';
import JetButton from '@/Components/Button.vue';
import JetFormSection from '@/Components/FormSection.vue';
import JetInput from '@/Components/Input.vue';
import JetInputError from '@/Components/InputError.vue';
import JetLabel from '@/Components/Label.vue';
const passwordInput = ref(null);
const currentPasswordInput = ref(null);
const form = useForm({
current_password: '',
password: '',
password_confirmation: '',
});
const updatePassword = () => {
form.put(route('user-password.update'), {
errorBag: 'updatePassword',
preserveScroll: true,
onSuccess: () => form.reset(),
onError: () => {
if (form.errors.password) {
form.reset('password', 'password_confirmation');
passwordInput.value.focus();
}
if (form.errors.current_password) {
form.reset('current_password');
currentPasswordInput.value.focus();
}
},
});
};
</script>
<template>
<JetFormSection @submitted="updatePassword">
<template #title>
Update Password
</template>
<template #description>
Ensure your account is using a long, random password to stay secure.
</template>
<template #form>
<div class="col-span-6 sm:col-span-4">
<JetLabel for="current_password" value="Current Password" />
<JetInput
id="current_password"
ref="currentPasswordInput"
v-model="form.current_password"
type="password"
class="mt-1 block w-full"
autocomplete="current-password"
/>
<JetInputError :message="form.errors.current_password" class="mt-2" />
</div>
<div class="col-span-6 sm:col-span-4">
<JetLabel for="password" value="New Password" />
<JetInput
id="password"
ref="passwordInput"
v-model="form.password"
type="password"
class="mt-1 block w-full"
autocomplete="new-password"
/>
<JetInputError :message="form.errors.password" class="mt-2" />
</div>
<div class="col-span-6 sm:col-span-4">
<JetLabel for="password_confirmation" value="Confirm Password" />
<JetInput
id="password_confirmation"
v-model="form.password_confirmation"
type="password"
class="mt-1 block w-full"
autocomplete="new-password"
/>
<JetInputError :message="form.errors.password_confirmation" class="mt-2" />
</div>
</template>
<template #actions>
<JetActionMessage :on="form.recentlySuccessful" class="mr-3">
Saved.
</JetActionMessage>
<JetButton :class="{ 'opacity-25': form.processing }" :disabled="form.processing">
Save
</JetButton>
</template>
</JetFormSection>
</template>