|
11 | 11 | <dt>{{ $t('pageChangePassword.username') }}</dt>
|
12 | 12 | <dd>{{ username }}</dd>
|
13 | 13 | </dl>
|
14 |
| - <b-form novalidate @submit.prevent="changePassword"> |
15 |
| - <b-form-group |
| 14 | + <b-form novalidate @submit.prevent="changePassword()"> |
| 15 | + <BFormGroup |
16 | 16 | label-for="password"
|
17 | 17 | :label="$t('pageChangePassword.newPassword')"
|
18 | 18 | >
|
19 | 19 | <template #label>
|
20 | 20 | {{ $t('pageUserManagement.modal.userPassword') }}
|
21 | 21 | <info-tooltip-password />
|
22 | 22 | </template>
|
23 |
| - <input-password-toggle> |
24 |
| - <b-form-input |
| 23 | + <input-password-toggle @updatePassView="updatePasswordType"> |
| 24 | + <BFormInput |
25 | 25 | id="password"
|
26 | 26 | v-model="form.password"
|
27 | 27 | autocomplete="off"
|
28 | 28 | autofocus="autofocus"
|
29 |
| - type="password" |
30 |
| - :state="getValidationState($v.form.password)" |
| 29 | + :type="inputType" |
| 30 | + :state="getValidationState(v$.form.password)" |
31 | 31 | class="form-control-with-button"
|
32 |
| - @change="$v.form.password.$touch()" |
33 |
| - > |
34 |
| - </b-form-input> |
35 |
| - <b-form-invalid-feedback role="alert"> |
36 |
| - <template v-if="!$v.form.password.required"> |
| 32 | + @input="v$.form.password.$touch()" |
| 33 | + /> |
| 34 | + <BFormInvalidFeedback role="alert"> |
| 35 | + <template v-if="v$.form.password.required.$invalid"> |
37 | 36 | {{ $t('global.form.fieldRequired') }}
|
38 | 37 | </template>
|
39 |
| - </b-form-invalid-feedback> |
| 38 | + </BFormInvalidFeedback> |
40 | 39 | </input-password-toggle>
|
41 |
| - </b-form-group> |
42 |
| - <b-form-group |
| 40 | + </BFormGroup> |
| 41 | + <BFormGroup |
43 | 42 | label-for="password-confirm"
|
44 | 43 | :label="$t('pageChangePassword.confirmNewPassword')"
|
45 | 44 | >
|
46 |
| - <input-password-toggle> |
47 |
| - <b-form-input |
| 45 | + <input-password-toggle @updatePassView="updateConfirmPasswordType"> |
| 46 | + <BFormInput |
48 | 47 | id="password-confirm"
|
49 | 48 | v-model="form.passwordConfirm"
|
50 | 49 | autocomplete="off"
|
51 |
| - type="password" |
52 |
| - :state="getValidationState($v.form.passwordConfirm)" |
| 50 | + :type="confirmPasswordType" |
| 51 | + :state="getValidationState(v$.form.passwordConfirm)" |
53 | 52 | class="form-control-with-button"
|
54 |
| - @change="$v.form.passwordConfirm.$touch()" |
55 |
| - > |
56 |
| - </b-form-input> |
57 |
| - <b-form-invalid-feedback role="alert"> |
58 |
| - <template v-if="!$v.form.passwordConfirm.required"> |
| 53 | + @input="v$.form.passwordConfirm.$touch()" |
| 54 | + /> |
| 55 | + <BFormInvalidFeedback role="alert"> |
| 56 | + <template v-if="v$.form.passwordConfirm.required.$invalid"> |
59 | 57 | {{ $t('global.form.fieldRequired') }}
|
60 | 58 | </template>
|
61 |
| - <template v-else-if="!$v.form.passwordConfirm.sameAsPassword"> |
| 59 | + <template v-else-if="v$.form.passwordConfirm.$errors.length > 0 ? v$.form.passwordConfirm.$errors[0].$validator === 'sameAsPassword' : false"> |
62 | 60 | {{ $t('global.form.passwordsDoNotMatch') }}
|
63 | 61 | </template>
|
64 |
| - </b-form-invalid-feedback> |
| 62 | + </BFormInvalidFeedback> |
65 | 63 | </input-password-toggle>
|
66 |
| - </b-form-group> |
| 64 | + </BFormGroup> |
67 | 65 | <div class="text-right">
|
68 | 66 | <b-button type="button" variant="link" @click="goBack">
|
69 | 67 | {{ $t('pageChangePassword.goBack') }}
|
|
77 | 75 | </div>
|
78 | 76 | </template>
|
79 | 77 |
|
80 |
| -<script> |
81 |
| -import { required, sameAs } from 'vuelidate/lib/validators'; |
82 |
| -import Alert from '@/components/Global/Alert'; |
83 |
| -import VuelidateMixin from '@/components/Mixins/VuelidateMixin'; |
84 |
| -import InfoTooltipPassword from '@/components/Global/InfoTooltipPassword'; |
85 |
| -import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
86 |
| -import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| 78 | +<script setup> |
| 79 | +import { ref, computed} from 'vue' |
| 80 | +import i18n from '@/i18n'; |
| 81 | +import { UserManagementStore, GlobalStore, AuthenticationStore } from '@/store'; |
| 82 | +import { required, sameAs } from '@vuelidate/validators'; |
| 83 | +import useVuelidateComposable from '@/components/Composables/useVuelidateComposable'; |
| 84 | +import { useVuelidate } from '@vuelidate/core'; |
| 85 | +import Alert from '@/components/Global/Alert.vue'; |
| 86 | +import InfoTooltipPassword from '@/components/Global/InfoTooltipPassword.vue'; |
| 87 | +import InputPasswordToggle from '@/components/Global/InputPasswordToggle.vue'; |
| 88 | +import { useRouter } from 'vue-router'; |
87 | 89 |
|
88 |
| -export default { |
89 |
| - name: 'ChangePassword', |
90 |
| - components: { Alert, InfoTooltipPassword, InputPasswordToggle }, |
91 |
| - mixins: [VuelidateMixin, BVToastMixin], |
92 |
| - data() { |
93 |
| - return { |
94 |
| - form: { |
95 |
| - password: null, |
96 |
| - passwordConfirm: null, |
97 |
| - }, |
98 |
| - username: this.$store.getters['global/username'], |
99 |
| - changePasswordError: false, |
100 |
| - }; |
101 |
| - }, |
102 |
| - validations() { |
103 |
| - return { |
| 90 | +const global = GlobalStore(); |
| 91 | +const userManagementStore = UserManagementStore(); |
| 92 | +const authenticationStore = AuthenticationStore(); |
| 93 | +
|
| 94 | +const router = useRouter(); |
| 95 | +const { getValidationState } = useVuelidateComposable(); |
| 96 | +
|
| 97 | +const form = ref({ |
| 98 | + password: '', |
| 99 | + passwordConfirm: '', |
| 100 | + }); |
| 101 | +const username = ref(global.usernameGetter); |
| 102 | +const changePasswordError = ref(false); |
| 103 | +const inputType = ref('password') |
| 104 | +const confirmPasswordType = ref('password') |
| 105 | +
|
| 106 | +const rules = computed(() => ({ |
104 | 107 | form: {
|
105 | 108 | password: { required },
|
106 | 109 | passwordConfirm: {
|
107 | 110 | required,
|
108 |
| - sameAsPassword: sameAs('password'), |
| 111 | + sameAsPassword: sameAs(form.value.password), |
109 | 112 | },
|
110 | 113 | },
|
111 |
| - }; |
112 |
| - }, |
113 |
| - methods: { |
114 |
| - goBack() { |
| 114 | + })); |
| 115 | +const v$ = useVuelidate(rules, {form}); |
| 116 | +
|
| 117 | +const goBack = () => { |
115 | 118 | // Remove session created if navigating back to the Login page
|
116 |
| - this.$store.dispatch('authentication/logout'); |
117 |
| - }, |
118 |
| - changePassword() { |
119 |
| - this.$v.$touch(); |
120 |
| - if (this.$v.$invalid) return; |
| 119 | + authenticationStore.logout().then(() => { |
| 120 | + router.push('/login'); |
| 121 | + }); |
| 122 | + }; |
| 123 | +const changePassword = () => { |
| 124 | + v$.value.$touch(); |
| 125 | + if (v$.value.$invalid) return; |
121 | 126 | let data = {
|
122 |
| - originalUsername: this.username, |
123 |
| - password: this.form.password, |
| 127 | + originalUsername: username.value, |
| 128 | + password: form.value.password, |
124 | 129 | };
|
125 | 130 |
|
126 |
| - this.$store |
127 |
| - .dispatch('userManagement/updateUser', data) |
| 131 | + userManagementStore.updateUser(data) |
128 | 132 | .then(() => {
|
129 | 133 | Promise.all([
|
130 |
| - this.$store.dispatch('userManagement/getUsers'), |
131 |
| - this.$store.dispatch('global/getCurrentUser', this.username), |
132 |
| - this.$store.dispatch('global/getSystemInfo'), |
133 |
| - ]); |
| 134 | + userManagementStore.getUsers(), |
| 135 | + global.getCurrentUser(username.value), |
| 136 | + global.getSystemInfo(), |
| 137 | + ]) |
| 138 | + v$.value.$reset(); |
134 | 139 | })
|
135 |
| - .then(() => this.$router.push('/')) |
136 |
| - .catch(() => (this.changePasswordError = true)); |
137 |
| - }, |
138 |
| - }, |
| 140 | + .then(() => router.push('/')) |
| 141 | + .catch(() => (changePasswordError.value = true)); |
| 142 | + }; |
| 143 | +const updatePasswordType = (passwordType) => { |
| 144 | + inputType.value=passwordType |
| 145 | +}; |
| 146 | +const updateConfirmPasswordType = (passwordType) => { |
| 147 | + confirmPasswordType.value=passwordType |
139 | 148 | };
|
140 | 149 | </script>
|
141 |
| - |
142 | 150 | <style lang="scss" scoped>
|
143 | 151 | .change-password__form-container {
|
144 | 152 | @include media-breakpoint-up('md') {
|
|
0 commit comments