-
-
Notifications
You must be signed in to change notification settings - Fork 568
/
Copy pathChangePassword.vue
119 lines (109 loc) · 3.76 KB
/
ChangePassword.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<template>
<popover placement="bottom" ref="popper">
<button slot="trigger" class="btn" v-text="__('Change Password')" />
<div class="saving-overlay flex justify-center text-center" v-if="saving">
<loading-graphic :text="__('Saving')" />
</div>
<div class="publish-fields w-96 p-4 pb-0">
<form-group
v-if="requiresCurrentPassword"
handle="password"
:display="__('Current Password')"
v-model="currentPassword"
:errors="errors.current_password"
class="mb-6 p-0"
:config="{ input_type: this.inputType }"
/>
<form-group
handle="password"
:display="__('Password')"
v-model="password"
:errors="errors.password"
class="mb-6 p-0"
:config="{ input_type: this.inputType }"
/>
<form-group
handle="confirmation"
:display="__('Password Confirmation')"
v-model="confirmation"
class="mb-6 p-0"
:config="{ input_type: this.inputType }"
/>
</div>
<div class="bg-gray-21 flex items-center rounded-b border-t px-4 py-2 dark:border-dark-900 dark:bg-dark-575">
<button class="btn-primary" @click.prevent="save">{{ __('Change Password') }}</button>
<label class="ltr:ml-4 rtl:mr-4">
<input type="checkbox" v-model="reveal" />
{{ __('Reveal Password') }}
</label>
</div>
</popover>
</template>
<script>
import HasElevatedSession from '@statamic/mixins/HasElevatedSession.js';
export default {
mixins: [HasElevatedSession],
props: {
saveUrl: String,
requiresCurrentPassword: Boolean,
},
data() {
return {
saving: false,
error: null,
errors: {},
currentPassword: null,
password: null,
confirmation: null,
reveal: false,
};
},
computed: {
hasErrors() {
return this.error || Object.keys(this.errors).length;
},
inputType() {
return this.reveal ? 'text' : 'password';
},
},
methods: {
clearErrors() {
this.error = null;
this.errors = {};
},
save() {
this.requireElevatedSession().then(() => this.performSaveRequest());
},
performSaveRequest() {
this.clearErrors();
this.saving = true;
this.$axios
.patch(this.saveUrl, {
current_password: this.currentPassword,
password: this.password,
password_confirmation: this.confirmation,
})
.then((response) => {
this.$toast.success(__('Password changed'));
this.$refs.popper.close();
this.saving = false;
this.password = null;
this.currentPassword = null;
this.confirmation = null;
})
.catch((e) => {
if (e.response && e.response.status === 422) {
const { message, errors } = e.response.data;
this.error = message;
this.errors = errors;
this.$toast.error(message);
this.saving = false;
} else {
this.$toast.error(__('Unable to change password'));
this.saving = false;
}
});
},
},
};
</script>