blob: 2e6cec6339631936eeef8142808fe62d67bd2bf9 [file] [log] [blame]
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +05301<template>
2 <b-container fluid="xl">
3 <page-title />
4
5 <b-row>
6 <b-col md="8" lg="8" xl="6">
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +05307 <page-section
8 :section-title="$t('pageProfileSettings.profileInfoTitle')"
9 >
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053010 <dl>
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053011 <dt>{{ $t('pageProfileSettings.username') }}</dt>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053012 <dd>
13 {{ username }}
14 </dd>
15 </dl>
16 </page-section>
17 </b-col>
18 </b-row>
19
20 <b-form @submit.prevent="submitForm">
jason westoverd36ac8a2025-11-03 20:58:59 -060021 <!-- 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 Pandeyb1f559f2020-04-28 20:18:28 +053031 <b-row>
32 <b-col sm="8" md="6" xl="3">
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053033 <page-section
34 :section-title="$t('pageProfileSettings.changePassword')"
35 >
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053036 <b-form-group
Damian Celicobcb0ab42022-08-23 03:18:58 +020037 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 westoverd36ac8a2025-11-03 20:58:59 -060046 autocomplete="current-password"
Damian Celicobcb0ab42022-08-23 03:18:58 +020047 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 Pandeyb1f559f2020-04-28 20:18:28 +053053 id="input-group-1"
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053054 :label="$t('pageProfileSettings.newPassword')"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053055 label-for="input-1"
56 >
57 <b-form-text id="password-help-block">
58 {{
Sandeepa Singhb4406162021-07-26 15:05:39 +053059 $t('pageUserManagement.modal.passwordMustBeBetween', {
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053060 min: passwordRequirements.minLength,
Derick Montague602e98a2020-10-21 16:20:00 -050061 max: passwordRequirements.maxLength,
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053062 })
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 westoverd36ac8a2025-11-03 20:58:59 -060071 autocomplete="new-password"
Surya Vde23ea22024-07-11 15:19:46 +053072 :state="getValidationState(v$.form.newPassword)"
Sukanya Pandey4334d262020-07-29 11:12:06 +053073 data-test-id="profileSettings-input-newPassword"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -050074 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +053075 @input="v$.form.newPassword.$touch()"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053076 />
77 <b-form-invalid-feedback role="alert">
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053078 <template
79 v-if="
Surya Venkatesan69be8242024-09-23 19:55:06 +053080 v$.form.newPassword.minLength.$invalid ||
81 v$.form.newPassword.maxLength.$invalid
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053082 "
83 >
84 {{
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +053085 $t('pageProfileSettings.newPassLabelTextInfo', {
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053086 min: passwordRequirements.minLength,
Derick Montague602e98a2020-10-21 16:20:00 -050087 max: passwordRequirements.maxLength,
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053088 })
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 Pandeyfc16f3c2020-06-23 22:54:27 +053096 :label="$t('pageProfileSettings.confirmPassword')"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +053097 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 westoverd36ac8a2025-11-03 20:58:59 -0600104 autocomplete="new-password"
Surya Vde23ea22024-07-11 15:19:46 +0530105 :state="getValidationState(v$.form.confirmPassword)"
Sukanya Pandey4334d262020-07-29 11:12:06 +0530106 data-test-id="profileSettings-input-confirmPassword"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -0500107 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +0530108 @input="v$.form.confirmPassword.$touch()"
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530109 />
110 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +0530111 <template
112 v-if="v$.form.confirmPassword.sameAsPassword.$invalid"
113 >
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530114 {{ $t('pageProfileSettings.passwordsDoNotMatch') }}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530115 </template>
116 </b-form-invalid-feedback>
117 </input-password-toggle>
118 </b-form-group>
119 </page-section>
120 </b-col>
121 </b-row>
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530122 <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 Pandey4334d262020-07-29 11:12:06 +0530130 data-test-id="profileSettings-radio-defaultUTC"
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530131 >
132 {{ $t('pageProfileSettings.defaultUTC') }}
133 </b-form-radio>
134 <b-form-radio
135 v-model="form.isUtcDisplay"
136 :value="false"
Sukanya Pandey4334d262020-07-29 11:12:06 +0530137 data-test-id="profileSettings-radio-browserOffset"
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530138 >
139 {{
140 $t('pageProfileSettings.browserOffset', {
Derick Montague602e98a2020-10-21 16:20:00 -0500141 timezone,
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530142 })
143 }}
144 </b-form-radio>
145 </b-form-group>
146 </b-col>
147 </b-row>
148 </page-section>
Sukanya Pandey4334d262020-07-29 11:12:06 +0530149 <b-button
150 variant="primary"
151 type="submit"
152 data-test-id="profileSettings-button-saveSettings"
153 >
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530154 {{ $t('global.action.saveSettings') }}
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530155 </b-button>
156 </b-form>
157 </b-container>
158</template>
159
160<script>
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530161import BVToastMixin from '@/components/Mixins/BVToastMixin';
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530162import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700163import { maxLength, minLength, sameAs } from '@vuelidate/validators';
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530164import LoadingBarMixin from '@/components/Mixins/LoadingBarMixin';
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500165import LocalTimezoneLabelMixin from '@/components/Mixins/LocalTimezoneLabelMixin';
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530166import PageTitle from '@/components/Global/PageTitle';
167import PageSection from '@/components/Global/PageSection';
168import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700169import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +0530170import { useI18n } from 'vue-i18n';
171import i18n from '@/i18n';
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530172
173export default {
174 name: 'ProfileSettings',
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530175 components: { InputPasswordToggle, PageSection, PageTitle },
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500176 mixins: [
177 BVToastMixin,
178 LocalTimezoneLabelMixin,
179 LoadingBarMixin,
Derick Montague602e98a2020-10-21 16:20:00 -0500180 VuelidateMixin,
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500181 ],
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700182 setup() {
183 return {
184 v$: useVuelidate(),
185 };
186 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530187 data() {
188 return {
Surya Vde23ea22024-07-11 15:19:46 +0530189 $t: useI18n().t,
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530190 form: {
191 newPassword: '',
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530192 confirmPassword: '',
Damian Celicobcb0ab42022-08-23 03:18:58 +0200193 currentPassword: '',
Derick Montague602e98a2020-10-21 16:20:00 -0500194 isUtcDisplay: this.$store.getters['global/isUtcDisplay'],
195 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530196 };
197 },
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530198 computed: {
199 username() {
200 return this.$store.getters['global/username'];
201 },
202 passwordRequirements() {
Sandeepa Singhb4406162021-07-26 15:05:39 +0530203 return this.$store.getters['userManagement/accountPasswordRequirements'];
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530204 },
205 timezone() {
Dixsie Wolmersfcda2002020-07-29 14:18:44 -0500206 return this.localOffset();
Derick Montague602e98a2020-10-21 16:20:00 -0500207 },
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530208 },
209 created() {
210 this.startLoader();
211 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530212 .dispatch('userManagement/getAccountSettings')
Sukanya Pandeyb93608d2020-07-10 18:51:58 +0530213 .finally(() => this.endLoader());
214 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530215 validations() {
216 return {
217 form: {
218 newPassword: {
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530219 minLength: minLength(this.passwordRequirements.minLength),
Derick Montague602e98a2020-10-21 16:20:00 -0500220 maxLength: maxLength(this.passwordRequirements.maxLength),
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530221 },
222 confirmPassword: {
Vladimir Novikov7fb9bb42025-04-24 14:24:23 +0300223 sameAsPassword: sameAs(this.form.newPassword),
Derick Montague602e98a2020-10-21 16:20:00 -0500224 },
225 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530226 };
227 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530228 methods: {
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530229 saveNewPasswordInputData() {
Surya Vde23ea22024-07-11 15:19:46 +0530230 this.v$.form.confirmPassword.$touch();
231 this.v$.form.newPassword.$touch();
232 if (this.v$.$invalid) return;
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530233 let userData = {
234 originalUsername: this.username,
Derick Montague602e98a2020-10-21 16:20:00 -0500235 password: this.form.newPassword,
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530236 };
237
238 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530239 .dispatch('userManagement/updateUser', userData)
Derick Montague602e98a2020-10-21 16:20:00 -0500240 .then((message) => {
Damian Celicobcb0ab42022-08-23 03:18:58 +0200241 (this.form.newPassword = ''),
242 (this.form.confirmPassword = ''),
243 (this.form.currentPassword = '');
Surya Vde23ea22024-07-11 15:19:46 +0530244 this.v$.$reset();
Sukanya Pandey9422e1a2020-07-13 19:13:07 +0530245 this.successToast(message);
Damian Celicobcb0ab42022-08-23 03:18:58 +0200246 this.$store.dispatch('authentication/logout');
Sukanya Pandey9422e1a2020-07-13 19:13:07 +0530247 })
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530248 .catch(({ message }) => this.errorToast(message));
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530249 },
250 saveTimeZonePrefrenceData() {
251 localStorage.setItem('storedUtcDisplay', this.form.isUtcDisplay);
252 this.$store.commit('global/setUtcTime', this.form.isUtcDisplay);
253 this.successToast(
Surya Vde23ea22024-07-11 15:19:46 +0530254 i18n.global.t('pageProfileSettings.toast.successUpdatingTimeZone'),
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530255 );
256 },
257 submitForm() {
Damian Celicobcb0ab42022-08-23 03:18:58 +0200258 if (
259 this.form.confirmPassword &&
260 this.form.newPassword &&
261 this.form.currentPassword
262 ) {
263 this.confirmAuthenticate();
Sukanya Pandeyfc16f3c2020-06-23 22:54:27 +0530264 }
Damian Celicobcb0ab42022-08-23 03:18:58 +0200265 if (
266 this.$store.getters['global/isUtcDisplay'] != this.form.isUtcDisplay
267 ) {
268 this.saveTimeZonePrefrenceData();
269 }
270 },
271 confirmAuthenticate() {
Surya Vde23ea22024-07-11 15:19:46 +0530272 this.v$.form.newPassword.$touch();
273 if (this.v$.$invalid) return;
Damian Celicobcb0ab42022-08-23 03:18:58 +0200274
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 Vde23ea22024-07-11 15:19:46 +0530284 this.v$.$reset();
Damian Celicobcb0ab42022-08-23 03:18:58 +0200285 this.errorToast(
Surya Vde23ea22024-07-11 15:19:46 +0530286 i18n.global.t('pageProfileSettings.toast.wrongCredentials'),
Damian Celicobcb0ab42022-08-23 03:18:58 +0200287 );
288 });
Derick Montague602e98a2020-10-21 16:20:00 -0500289 },
290 },
Sukanya Pandeyb1f559f2020-04-28 20:18:28 +0530291};
292</script>