blob: f829229a4b7509c7c04e0eabe3ba529a047fa6bf [file] [log] [blame]
Yoshie Muranaka33058572020-06-16 13:21:21 -07001<template>
Derick Montague932aff92021-08-26 14:06:49 -05002 <div class="change-password-container">
Yoshie Muranaka33058572020-06-16 13:21:21 -07003 <alert variant="danger" class="mb-4">
Yoshie Muranaka2c98b092020-06-22 13:28:09 -07004 <p v-if="changePasswordError">
5 {{ $t('pageChangePassword.changePasswordError') }}
6 </p>
jason westoverd36ac8a2025-11-03 20:58:59 -06007 <p v-else>
8 {{ $t('pageChangePassword.changePasswordAlertMessage') }}
9 </p>
Yoshie Muranaka33058572020-06-16 13:21:21 -070010 </alert>
Derick Montague932aff92021-08-26 14:06:49 -050011 <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 westoverd36ac8a2025-11-03 20:58:59 -060027 autocomplete="new-password"
Surya Vde23ea22024-07-11 15:19:46 +053028 :state="getValidationState(v$.form.password)"
Derick Montague932aff92021-08-26 14:06:49 -050029 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +053030 @change="v$.form.password.$touch()"
Derick Montague932aff92021-08-26 14:06:49 -050031 >
32 </b-form-input>
33 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053034 <template v-if="v$.form.password.required.$invalid">
Derick Montague932aff92021-08-26 14:06:49 -050035 {{ $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 westoverd36ac8a2025-11-03 20:58:59 -060049 autocomplete="new-password"
Surya Vde23ea22024-07-11 15:19:46 +053050 :state="getValidationState(v$.form.passwordConfirm)"
Derick Montague932aff92021-08-26 14:06:49 -050051 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +053052 @change="v$.form.passwordConfirm.$touch()"
Derick Montague932aff92021-08-26 14:06:49 -050053 >
54 </b-form-input>
55 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053056 <template v-if="v$.form.passwordConfirm.required.$invalid">
Derick Montague932aff92021-08-26 14:06:49 -050057 {{ $t('global.form.fieldRequired') }}
58 </template>
Surya Venkatesan69be8242024-09-23 19:55:06 +053059 <template
60 v-else-if="v$.form.passwordConfirm.sameAsPassword.$invalid"
61 >
Derick Montague932aff92021-08-26 14:06:49 -050062 {{ $t('global.form.passwordsDoNotMatch') }}
63 </template>
64 </b-form-invalid-feedback>
65 </input-password-toggle>
66 </b-form-group>
jason westoverd36ac8a2025-11-03 20:58:59 -060067 <div class="text-end">
Derick Montague932aff92021-08-26 14:06:49 -050068 <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 Muranaka33058572020-06-16 13:21:21 -070077 </div>
78</template>
79
80<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070081import { required, sameAs } from '@vuelidate/validators';
Yoshie Muranaka33058572020-06-16 13:21:21 -070082import Alert from '@/components/Global/Alert';
83import VuelidateMixin from '@/components/Mixins/VuelidateMixin';
84import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070085import BVToastMixin from '@/components/Mixins/BVToastMixin';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070086import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053087import { useI18n } from 'vue-i18n';
Yoshie Muranaka33058572020-06-16 13:21:21 -070088
89export default {
90 name: 'ChangePassword',
91 components: { Alert, InputPasswordToggle },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070092 mixins: [VuelidateMixin, BVToastMixin],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070093 setup() {
94 return {
95 v$: useVuelidate(),
96 };
97 },
Yoshie Muranaka33058572020-06-16 13:21:21 -070098 data() {
99 return {
Surya Vde23ea22024-07-11 15:19:46 +0530100 $t: useI18n().t,
Yoshie Muranaka33058572020-06-16 13:21:21 -0700101 form: {
102 password: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500103 passwordConfirm: null,
Yoshie Muranaka33058572020-06-16 13:21:21 -0700104 },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700105 username: this.$store.getters['global/username'],
Derick Montague602e98a2020-10-21 16:20:00 -0500106 changePasswordError: false,
Yoshie Muranaka33058572020-06-16 13:21:21 -0700107 };
108 },
109 validations() {
110 return {
111 form: {
112 password: { required },
113 passwordConfirm: {
114 required,
Vladimir Novikov7fb9bb42025-04-24 14:24:23 +0300115 sameAsPassword: sameAs(this.form.password),
Derick Montague602e98a2020-10-21 16:20:00 -0500116 },
117 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700118 };
119 },
120 methods: {
121 goBack() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700122 // Remove session created if navigating back to the Login page
123 this.$store.dispatch('authentication/logout');
Yoshie Muranaka33058572020-06-16 13:21:21 -0700124 },
125 changePassword() {
Surya Vde23ea22024-07-11 15:19:46 +0530126 this.v$.$touch();
127 if (this.v$.$invalid) return;
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700128 let data = {
129 originalUsername: this.username,
Derick Montague602e98a2020-10-21 16:20:00 -0500130 password: this.form.password,
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700131 };
132
133 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530134 .dispatch('userManagement/updateUser', data)
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700135 .then(() => this.$router.push('/'))
136 .catch(() => (this.changePasswordError = true));
Derick Montague602e98a2020-10-21 16:20:00 -0500137 },
138 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700139};
140</script>
141
142<style lang="scss" scoped>
Derick Montague932aff92021-08-26 14:06:49 -0500143.change-password__form-container {
144 @include media-breakpoint-up('md') {
145 max-width: 360px;
146 }
Yoshie Muranaka33058572020-06-16 13:21:21 -0700147}
148</style>