| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 1 | <template> |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 2 | <div class="change-password-container"> |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 3 | <alert variant="danger" class="mb-4"> |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 4 | <p v-if="changePasswordError"> |
| 5 | {{ $t('pageChangePassword.changePasswordError') }} |
| 6 | </p> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 7 | <p v-else> |
| 8 | {{ $t('pageChangePassword.changePasswordAlertMessage') }} |
| 9 | </p> |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 10 | </alert> |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 11 | <div class="change-password__form-container"> |
| 12 | <dl> |
| 13 | <dt>{{ $t('pageChangePassword.username') }}</dt> |
| 14 | <dd>{{ username }}</dd> |
| 15 | </dl> |
| 16 | <b-form novalidate @submit.prevent="changePassword"> |
| 17 | <b-form-group |
| 18 | label-for="password" |
| 19 | :label="$t('pageChangePassword.newPassword')" |
| 20 | > |
| 21 | <input-password-toggle> |
| 22 | <b-form-input |
| 23 | id="password" |
| 24 | v-model="form.password" |
| 25 | autofocus="autofocus" |
| 26 | type="password" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 27 | autocomplete="new-password" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 28 | :state="getValidationState(v$.form.password)" |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 29 | class="form-control-with-button" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 30 | @change="v$.form.password.$touch()" |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 31 | > |
| 32 | </b-form-input> |
| 33 | <b-form-invalid-feedback role="alert"> |
| Surya Venkatesan | 69be824 | 2024-09-23 19:55:06 +0530 | [diff] [blame] | 34 | <template v-if="v$.form.password.required.$invalid"> |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 35 | {{ $t('global.form.fieldRequired') }} |
| 36 | </template> |
| 37 | </b-form-invalid-feedback> |
| 38 | </input-password-toggle> |
| 39 | </b-form-group> |
| 40 | <b-form-group |
| 41 | label-for="password-confirm" |
| 42 | :label="$t('pageChangePassword.confirmNewPassword')" |
| 43 | > |
| 44 | <input-password-toggle> |
| 45 | <b-form-input |
| 46 | id="password-confirm" |
| 47 | v-model="form.passwordConfirm" |
| 48 | type="password" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 49 | autocomplete="new-password" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 50 | :state="getValidationState(v$.form.passwordConfirm)" |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 51 | class="form-control-with-button" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 52 | @change="v$.form.passwordConfirm.$touch()" |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 53 | > |
| 54 | </b-form-input> |
| 55 | <b-form-invalid-feedback role="alert"> |
| Surya Venkatesan | 69be824 | 2024-09-23 19:55:06 +0530 | [diff] [blame] | 56 | <template v-if="v$.form.passwordConfirm.required.$invalid"> |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 57 | {{ $t('global.form.fieldRequired') }} |
| 58 | </template> |
| Surya Venkatesan | 69be824 | 2024-09-23 19:55:06 +0530 | [diff] [blame] | 59 | <template |
| 60 | v-else-if="v$.form.passwordConfirm.sameAsPassword.$invalid" |
| 61 | > |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 62 | {{ $t('global.form.passwordsDoNotMatch') }} |
| 63 | </template> |
| 64 | </b-form-invalid-feedback> |
| 65 | </input-password-toggle> |
| 66 | </b-form-group> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 67 | <div class="text-end"> |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 68 | <b-button type="button" variant="link" @click="goBack"> |
| 69 | {{ $t('pageChangePassword.goBack') }} |
| 70 | </b-button> |
| 71 | <b-button type="submit" variant="primary"> |
| 72 | {{ $t('pageChangePassword.changePassword') }} |
| 73 | </b-button> |
| 74 | </div> |
| 75 | </b-form> |
| 76 | </div> |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 77 | </div> |
| 78 | </template> |
| 79 | |
| 80 | <script> |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 81 | import { required, sameAs } from '@vuelidate/validators'; |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 82 | import Alert from '@/components/Global/Alert'; |
| 83 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin'; |
| 84 | import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 85 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 86 | import { useVuelidate } from '@vuelidate/core'; |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 87 | import { useI18n } from 'vue-i18n'; |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 88 | |
| 89 | export default { |
| 90 | name: 'ChangePassword', |
| 91 | components: { Alert, InputPasswordToggle }, |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 92 | mixins: [VuelidateMixin, BVToastMixin], |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 93 | setup() { |
| 94 | return { |
| 95 | v$: useVuelidate(), |
| 96 | }; |
| 97 | }, |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 98 | data() { |
| 99 | return { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 100 | $t: useI18n().t, |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 101 | form: { |
| 102 | password: null, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 103 | passwordConfirm: null, |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 104 | }, |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 105 | username: this.$store.getters['global/username'], |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 106 | changePasswordError: false, |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 107 | }; |
| 108 | }, |
| 109 | validations() { |
| 110 | return { |
| 111 | form: { |
| 112 | password: { required }, |
| 113 | passwordConfirm: { |
| 114 | required, |
| Vladimir Novikov | 7fb9bb4 | 2025-04-24 14:24:23 +0300 | [diff] [blame] | 115 | sameAsPassword: sameAs(this.form.password), |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 116 | }, |
| 117 | }, |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 118 | }; |
| 119 | }, |
| 120 | methods: { |
| 121 | goBack() { |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 122 | // Remove session created if navigating back to the Login page |
| 123 | this.$store.dispatch('authentication/logout'); |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 124 | }, |
| 125 | changePassword() { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 126 | this.v$.$touch(); |
| 127 | if (this.v$.$invalid) return; |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 128 | let data = { |
| 129 | originalUsername: this.username, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 130 | password: this.form.password, |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 131 | }; |
| 132 | |
| 133 | this.$store |
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 134 | .dispatch('userManagement/updateUser', data) |
| Yoshie Muranaka | 2c98b09 | 2020-06-22 13:28:09 -0700 | [diff] [blame] | 135 | .then(() => this.$router.push('/')) |
| 136 | .catch(() => (this.changePasswordError = true)); |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 137 | }, |
| 138 | }, |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 139 | }; |
| 140 | </script> |
| 141 | |
| 142 | <style lang="scss" scoped> |
| Derick Montague | 932aff9 | 2021-08-26 14:06:49 -0500 | [diff] [blame] | 143 | .change-password__form-container { |
| 144 | @include media-breakpoint-up('md') { |
| 145 | max-width: 360px; |
| 146 | } |
| Yoshie Muranaka | 3305857 | 2020-06-16 13:21:21 -0700 | [diff] [blame] | 147 | } |
| 148 | </style> |