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