blob: 7778ebee1037c3e7bf097c5d49f185f27b9657ec [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>
7 <p v-else>{{ $t('pageChangePassword.changePasswordAlertMessage') }}</p>
Yoshie Muranaka33058572020-06-16 13:21:21 -07008 </alert>
Derick Montague932aff92021-08-26 14:06:49 -05009 <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 Vde23ea22024-07-11 15:19:46 +053025 :state="getValidationState(v$.form.password)"
Derick Montague932aff92021-08-26 14:06:49 -050026 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +053027 @change="v$.form.password.$touch()"
Derick Montague932aff92021-08-26 14:06:49 -050028 >
29 </b-form-input>
30 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053031 <template v-if="v$.form.password.required.$invalid">
Derick Montague932aff92021-08-26 14:06:49 -050032 {{ $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 Vde23ea22024-07-11 15:19:46 +053046 :state="getValidationState(v$.form.passwordConfirm)"
Derick Montague932aff92021-08-26 14:06:49 -050047 class="form-control-with-button"
Surya Vde23ea22024-07-11 15:19:46 +053048 @change="v$.form.passwordConfirm.$touch()"
Derick Montague932aff92021-08-26 14:06:49 -050049 >
50 </b-form-input>
51 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053052 <template v-if="v$.form.passwordConfirm.required.$invalid">
Derick Montague932aff92021-08-26 14:06:49 -050053 {{ $t('global.form.fieldRequired') }}
54 </template>
Surya Venkatesan69be8242024-09-23 19:55:06 +053055 <template
56 v-else-if="v$.form.passwordConfirm.sameAsPassword.$invalid"
57 >
Derick Montague932aff92021-08-26 14:06:49 -050058 {{ $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 Muranaka33058572020-06-16 13:21:21 -070073 </div>
74</template>
75
76<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070077import { required, sameAs } from '@vuelidate/validators';
Yoshie Muranaka33058572020-06-16 13:21:21 -070078import Alert from '@/components/Global/Alert';
79import VuelidateMixin from '@/components/Mixins/VuelidateMixin';
80import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070081import BVToastMixin from '@/components/Mixins/BVToastMixin';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070082import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053083import { useI18n } from 'vue-i18n';
Yoshie Muranaka33058572020-06-16 13:21:21 -070084
85export default {
86 name: 'ChangePassword',
87 components: { Alert, InputPasswordToggle },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070088 mixins: [VuelidateMixin, BVToastMixin],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070089 setup() {
90 return {
91 v$: useVuelidate(),
92 };
93 },
Yoshie Muranaka33058572020-06-16 13:21:21 -070094 data() {
95 return {
Surya Vde23ea22024-07-11 15:19:46 +053096 $t: useI18n().t,
Yoshie Muranaka33058572020-06-16 13:21:21 -070097 form: {
98 password: null,
Derick Montague602e98a2020-10-21 16:20:00 -050099 passwordConfirm: null,
Yoshie Muranaka33058572020-06-16 13:21:21 -0700100 },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700101 username: this.$store.getters['global/username'],
Derick Montague602e98a2020-10-21 16:20:00 -0500102 changePasswordError: false,
Yoshie Muranaka33058572020-06-16 13:21:21 -0700103 };
104 },
105 validations() {
106 return {
107 form: {
108 password: { required },
109 passwordConfirm: {
110 required,
Derick Montague602e98a2020-10-21 16:20:00 -0500111 sameAsPassword: sameAs('password'),
112 },
113 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700114 };
115 },
116 methods: {
117 goBack() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700118 // Remove session created if navigating back to the Login page
119 this.$store.dispatch('authentication/logout');
Yoshie Muranaka33058572020-06-16 13:21:21 -0700120 },
121 changePassword() {
Surya Vde23ea22024-07-11 15:19:46 +0530122 this.v$.$touch();
123 if (this.v$.$invalid) return;
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700124 let data = {
125 originalUsername: this.username,
Derick Montague602e98a2020-10-21 16:20:00 -0500126 password: this.form.password,
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700127 };
128
129 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530130 .dispatch('userManagement/updateUser', data)
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700131 .then(() => this.$router.push('/'))
132 .catch(() => (this.changePasswordError = true));
Derick Montague602e98a2020-10-21 16:20:00 -0500133 },
134 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700135};
136</script>
137
138<style lang="scss" scoped>
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700139@import '@/assets/styles/bmc/helpers/_index.scss';
140@import '@/assets/styles/bootstrap/_helpers.scss';
141
142@import '@/assets/styles/bootstrap/_helpers.scss';
143
Derick Montague932aff92021-08-26 14:06:49 -0500144.change-password__form-container {
145 @include media-breakpoint-up('md') {
146 max-width: 360px;
147 }
Yoshie Muranaka33058572020-06-16 13:21:21 -0700148}
149</style>