| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 1 | <template> |
| 2 | <b-container fluid="xl"> |
| 3 | <page-title /> |
| 4 | |
| 5 | <b-row> |
| 6 | <b-col md="8" lg="8" xl="6"> |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 7 | <page-section |
| 8 | :section-title="$t('pageProfileSettings.profileInfoTitle')" |
| 9 | > |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 10 | <dl> |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 11 | <dt>{{ $t('pageProfileSettings.username') }}</dt> |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 12 | <dd> |
| 13 | {{ username }} |
| 14 | </dd> |
| 15 | </dl> |
| 16 | </page-section> |
| 17 | </b-col> |
| 18 | </b-row> |
| 19 | |
| 20 | <b-form @submit.prevent="submitForm"> |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 21 | <!-- Hidden username field for browser autocomplete accessibility --> |
| 22 | <input |
| 23 | type="text" |
| 24 | name="username" |
| 25 | :value="username" |
| 26 | autocomplete="username" |
| 27 | class="visually-hidden" |
| 28 | aria-hidden="true" |
| 29 | tabindex="-1" |
| 30 | /> |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 31 | <b-row> |
| 32 | <b-col sm="8" md="6" xl="3"> |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 33 | <page-section |
| 34 | :section-title="$t('pageProfileSettings.changePassword')" |
| 35 | > |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 36 | <b-form-group |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 37 | id="input-group-0" |
| 38 | :label="$t('pageProfileSettings.currentPassword')" |
| 39 | label-for="input-0" |
| 40 | > |
| 41 | <input-password-toggle> |
| 42 | <b-form-input |
| 43 | id="old-password" |
| 44 | v-model="form.currentPassword" |
| 45 | type="password" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 46 | autocomplete="current-password" |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 47 | data-test-id="profileSettings-input-ocurrentPassword" |
| 48 | class="form-control-with-button" |
| 49 | /> |
| 50 | </input-password-toggle> |
| 51 | </b-form-group> |
| 52 | <b-form-group |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 53 | id="input-group-1" |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 54 | :label="$t('pageProfileSettings.newPassword')" |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 55 | label-for="input-1" |
| 56 | > |
| 57 | <b-form-text id="password-help-block"> |
| 58 | {{ |
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 59 | $t('pageUserManagement.modal.passwordMustBeBetween', { |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 60 | min: passwordRequirements.minLength, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 61 | max: passwordRequirements.maxLength, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 62 | }) |
| 63 | }} |
| 64 | </b-form-text> |
| 65 | <input-password-toggle> |
| 66 | <b-form-input |
| 67 | id="password" |
| 68 | v-model="form.newPassword" |
| 69 | type="password" |
| 70 | aria-describedby="password-help-block" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 71 | autocomplete="new-password" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 72 | :state="getValidationState(v$.form.newPassword)" |
| Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 73 | data-test-id="profileSettings-input-newPassword" |
| Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 74 | class="form-control-with-button" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 75 | @input="v$.form.newPassword.$touch()" |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 76 | /> |
| 77 | <b-form-invalid-feedback role="alert"> |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 78 | <template |
| 79 | v-if=" |
| Surya Venkatesan | 69be824 | 2024-09-23 19:55:06 +0530 | [diff] [blame] | 80 | v$.form.newPassword.minLength.$invalid || |
| 81 | v$.form.newPassword.maxLength.$invalid |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 82 | " |
| 83 | > |
| 84 | {{ |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 85 | $t('pageProfileSettings.newPassLabelTextInfo', { |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 86 | min: passwordRequirements.minLength, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 87 | max: passwordRequirements.maxLength, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 88 | }) |
| 89 | }} |
| 90 | </template> |
| 91 | </b-form-invalid-feedback> |
| 92 | </input-password-toggle> |
| 93 | </b-form-group> |
| 94 | <b-form-group |
| 95 | id="input-group-2" |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 96 | :label="$t('pageProfileSettings.confirmPassword')" |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 97 | label-for="input-2" |
| 98 | > |
| 99 | <input-password-toggle> |
| 100 | <b-form-input |
| 101 | id="password-confirmation" |
| 102 | v-model="form.confirmPassword" |
| 103 | type="password" |
| jason westover | d36ac8a | 2025-11-03 20:58:59 -0600 | [diff] [blame^] | 104 | autocomplete="new-password" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 105 | :state="getValidationState(v$.form.confirmPassword)" |
| Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 106 | data-test-id="profileSettings-input-confirmPassword" |
| Dixsie Wolmers | 5ea1678 | 2020-07-27 17:50:43 -0500 | [diff] [blame] | 107 | class="form-control-with-button" |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 108 | @input="v$.form.confirmPassword.$touch()" |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 109 | /> |
| 110 | <b-form-invalid-feedback role="alert"> |
| Surya Venkatesan | 69be824 | 2024-09-23 19:55:06 +0530 | [diff] [blame] | 111 | <template |
| 112 | v-if="v$.form.confirmPassword.sameAsPassword.$invalid" |
| 113 | > |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 114 | {{ $t('pageProfileSettings.passwordsDoNotMatch') }} |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 115 | </template> |
| 116 | </b-form-invalid-feedback> |
| 117 | </input-password-toggle> |
| 118 | </b-form-group> |
| 119 | </page-section> |
| 120 | </b-col> |
| 121 | </b-row> |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 122 | <page-section :section-title="$t('pageProfileSettings.timezoneDisplay')"> |
| 123 | <p>{{ $t('pageProfileSettings.timezoneDisplayDesc') }}</p> |
| 124 | <b-row> |
| 125 | <b-col md="9" lg="8" xl="9"> |
| 126 | <b-form-group :label="$t('pageProfileSettings.timezone')"> |
| 127 | <b-form-radio |
| 128 | v-model="form.isUtcDisplay" |
| 129 | :value="true" |
| Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 130 | data-test-id="profileSettings-radio-defaultUTC" |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 131 | > |
| 132 | {{ $t('pageProfileSettings.defaultUTC') }} |
| 133 | </b-form-radio> |
| 134 | <b-form-radio |
| 135 | v-model="form.isUtcDisplay" |
| 136 | :value="false" |
| Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 137 | data-test-id="profileSettings-radio-browserOffset" |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 138 | > |
| 139 | {{ |
| 140 | $t('pageProfileSettings.browserOffset', { |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 141 | timezone, |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 142 | }) |
| 143 | }} |
| 144 | </b-form-radio> |
| 145 | </b-form-group> |
| 146 | </b-col> |
| 147 | </b-row> |
| 148 | </page-section> |
| Sukanya Pandey | 4334d26 | 2020-07-29 11:12:06 +0530 | [diff] [blame] | 149 | <b-button |
| 150 | variant="primary" |
| 151 | type="submit" |
| 152 | data-test-id="profileSettings-button-saveSettings" |
| 153 | > |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 154 | {{ $t('global.action.saveSettings') }} |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 155 | </b-button> |
| 156 | </b-form> |
| 157 | </b-container> |
| 158 | </template> |
| 159 | |
| 160 | <script> |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 161 | import BVToastMixin from '@/components/Mixins/BVToastMixin'; |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 162 | import InputPasswordToggle from '@/components/Global/InputPasswordToggle'; |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 163 | import { maxLength, minLength, sameAs } from '@vuelidate/validators'; |
| Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 164 | import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin'; |
| Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 165 | import LocalTimezoneLabelMixin from '@/components/Mixins/LocalTimezoneLabelMixin'; |
| Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 166 | import PageTitle from '@/components/Global/PageTitle'; |
| 167 | import PageSection from '@/components/Global/PageSection'; |
| 168 | import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js'; |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 169 | import { useVuelidate } from '@vuelidate/core'; |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 170 | import { useI18n } from 'vue-i18n'; |
| 171 | import i18n from '@/i18n'; |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 172 | |
| 173 | export default { |
| 174 | name: 'ProfileSettings', |
| Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 175 | components: { InputPasswordToggle, PageSection, PageTitle }, |
| Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 176 | mixins: [ |
| 177 | BVToastMixin, |
| 178 | LocalTimezoneLabelMixin, |
| 179 | LoadingBarMixin, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 180 | VuelidateMixin, |
| Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 181 | ], |
| Ed Tanous | 7d6b44c | 2024-03-23 14:56:34 -0700 | [diff] [blame] | 182 | setup() { |
| 183 | return { |
| 184 | v$: useVuelidate(), |
| 185 | }; |
| 186 | }, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 187 | data() { |
| 188 | return { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 189 | $t: useI18n().t, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 190 | form: { |
| 191 | newPassword: '', |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 192 | confirmPassword: '', |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 193 | currentPassword: '', |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 194 | isUtcDisplay: this.$store.getters['global/isUtcDisplay'], |
| 195 | }, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 196 | }; |
| 197 | }, |
| Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 198 | computed: { |
| 199 | username() { |
| 200 | return this.$store.getters['global/username']; |
| 201 | }, |
| 202 | passwordRequirements() { |
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 203 | return this.$store.getters['userManagement/accountPasswordRequirements']; |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 204 | }, |
| 205 | timezone() { |
| Dixsie Wolmers | fcda200 | 2020-07-29 14:18:44 -0500 | [diff] [blame] | 206 | return this.localOffset(); |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 207 | }, |
| Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 208 | }, |
| 209 | created() { |
| 210 | this.startLoader(); |
| 211 | this.$store |
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 212 | .dispatch('userManagement/getAccountSettings') |
| Sukanya Pandey | b93608d | 2020-07-10 18:51:58 +0530 | [diff] [blame] | 213 | .finally(() => this.endLoader()); |
| 214 | }, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 215 | validations() { |
| 216 | return { |
| 217 | form: { |
| 218 | newPassword: { |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 219 | minLength: minLength(this.passwordRequirements.minLength), |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 220 | maxLength: maxLength(this.passwordRequirements.maxLength), |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 221 | }, |
| 222 | confirmPassword: { |
| Vladimir Novikov | 7fb9bb4 | 2025-04-24 14:24:23 +0300 | [diff] [blame] | 223 | sameAsPassword: sameAs(this.form.newPassword), |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 224 | }, |
| 225 | }, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 226 | }; |
| 227 | }, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 228 | methods: { |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 229 | saveNewPasswordInputData() { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 230 | this.v$.form.confirmPassword.$touch(); |
| 231 | this.v$.form.newPassword.$touch(); |
| 232 | if (this.v$.$invalid) return; |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 233 | let userData = { |
| 234 | originalUsername: this.username, |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 235 | password: this.form.newPassword, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 236 | }; |
| 237 | |
| 238 | this.$store |
| Sandeepa Singh | b440616 | 2021-07-26 15:05:39 +0530 | [diff] [blame] | 239 | .dispatch('userManagement/updateUser', userData) |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 240 | .then((message) => { |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 241 | (this.form.newPassword = ''), |
| 242 | (this.form.confirmPassword = ''), |
| 243 | (this.form.currentPassword = ''); |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 244 | this.v$.$reset(); |
| Sukanya Pandey | 9422e1a | 2020-07-13 19:13:07 +0530 | [diff] [blame] | 245 | this.successToast(message); |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 246 | this.$store.dispatch('authentication/logout'); |
| Sukanya Pandey | 9422e1a | 2020-07-13 19:13:07 +0530 | [diff] [blame] | 247 | }) |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 248 | .catch(({ message }) => this.errorToast(message)); |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 249 | }, |
| 250 | saveTimeZonePrefrenceData() { |
| 251 | localStorage.setItem('storedUtcDisplay', this.form.isUtcDisplay); |
| 252 | this.$store.commit('global/setUtcTime', this.form.isUtcDisplay); |
| 253 | this.successToast( |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 254 | i18n.global.t('pageProfileSettings.toast.successUpdatingTimeZone'), |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 255 | ); |
| 256 | }, |
| 257 | submitForm() { |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 258 | if ( |
| 259 | this.form.confirmPassword && |
| 260 | this.form.newPassword && |
| 261 | this.form.currentPassword |
| 262 | ) { |
| 263 | this.confirmAuthenticate(); |
| Sukanya Pandey | fc16f3c | 2020-06-23 22:54:27 +0530 | [diff] [blame] | 264 | } |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 265 | if ( |
| 266 | this.$store.getters['global/isUtcDisplay'] != this.form.isUtcDisplay |
| 267 | ) { |
| 268 | this.saveTimeZonePrefrenceData(); |
| 269 | } |
| 270 | }, |
| 271 | confirmAuthenticate() { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 272 | this.v$.form.newPassword.$touch(); |
| 273 | if (this.v$.$invalid) return; |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 274 | |
| 275 | const username = this.username; |
| 276 | const password = this.form.currentPassword; |
| 277 | |
| 278 | this.$store |
| 279 | .dispatch('authentication/login', { username, password }) |
| 280 | .then(() => { |
| 281 | this.saveNewPasswordInputData(); |
| 282 | }) |
| 283 | .catch(() => { |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 284 | this.v$.$reset(); |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 285 | this.errorToast( |
| Surya V | de23ea2 | 2024-07-11 15:19:46 +0530 | [diff] [blame] | 286 | i18n.global.t('pageProfileSettings.toast.wrongCredentials'), |
| Damian Celico | bcb0ab4 | 2022-08-23 03:18:58 +0200 | [diff] [blame] | 287 | ); |
| 288 | }); |
| Derick Montague | 602e98a | 2020-10-21 16:20:00 -0500 | [diff] [blame] | 289 | }, |
| 290 | }, |
| Sukanya Pandey | b1f559f | 2020-04-28 20:18:28 +0530 | [diff] [blame] | 291 | }; |
| 292 | </script> |