blob: 2680cc35be40385f305eb67e2559836bdc586656 [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 Vde23ea22024-07-11 15:19:46 +053031 <template v-if="!v$.form.password.required">
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 Vde23ea22024-07-11 15:19:46 +053052 <template v-if="!v$.form.passwordConfirm.required">
Derick Montague932aff92021-08-26 14:06:49 -050053 {{ $t('global.form.fieldRequired') }}
54 </template>
Surya Vde23ea22024-07-11 15:19:46 +053055 <template v-else-if="!v$.form.passwordConfirm.sameAsPassword">
Derick Montague932aff92021-08-26 14:06:49 -050056 {{ $t('global.form.passwordsDoNotMatch') }}
57 </template>
58 </b-form-invalid-feedback>
59 </input-password-toggle>
60 </b-form-group>
61 <div class="text-right">
62 <b-button type="button" variant="link" @click="goBack">
63 {{ $t('pageChangePassword.goBack') }}
64 </b-button>
65 <b-button type="submit" variant="primary">
66 {{ $t('pageChangePassword.changePassword') }}
67 </b-button>
68 </div>
69 </b-form>
70 </div>
Yoshie Muranaka33058572020-06-16 13:21:21 -070071 </div>
72</template>
73
74<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070075import { required, sameAs } from '@vuelidate/validators';
Yoshie Muranaka33058572020-06-16 13:21:21 -070076import Alert from '@/components/Global/Alert';
77import VuelidateMixin from '@/components/Mixins/VuelidateMixin';
78import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070079import BVToastMixin from '@/components/Mixins/BVToastMixin';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070080import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053081import { useI18n } from 'vue-i18n';
Yoshie Muranaka33058572020-06-16 13:21:21 -070082
83export default {
84 name: 'ChangePassword',
85 components: { Alert, InputPasswordToggle },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070086 mixins: [VuelidateMixin, BVToastMixin],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070087 setup() {
88 return {
89 v$: useVuelidate(),
90 };
91 },
Yoshie Muranaka33058572020-06-16 13:21:21 -070092 data() {
93 return {
Surya Vde23ea22024-07-11 15:19:46 +053094 $t: useI18n().t,
Yoshie Muranaka33058572020-06-16 13:21:21 -070095 form: {
96 password: null,
Derick Montague602e98a2020-10-21 16:20:00 -050097 passwordConfirm: null,
Yoshie Muranaka33058572020-06-16 13:21:21 -070098 },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070099 username: this.$store.getters['global/username'],
Derick Montague602e98a2020-10-21 16:20:00 -0500100 changePasswordError: false,
Yoshie Muranaka33058572020-06-16 13:21:21 -0700101 };
102 },
103 validations() {
104 return {
105 form: {
106 password: { required },
107 passwordConfirm: {
108 required,
Derick Montague602e98a2020-10-21 16:20:00 -0500109 sameAsPassword: sameAs('password'),
110 },
111 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700112 };
113 },
114 methods: {
115 goBack() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700116 // Remove session created if navigating back to the Login page
117 this.$store.dispatch('authentication/logout');
Yoshie Muranaka33058572020-06-16 13:21:21 -0700118 },
119 changePassword() {
Surya Vde23ea22024-07-11 15:19:46 +0530120 this.v$.$touch();
121 if (this.v$.$invalid) return;
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700122 let data = {
123 originalUsername: this.username,
Derick Montague602e98a2020-10-21 16:20:00 -0500124 password: this.form.password,
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700125 };
126
127 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530128 .dispatch('userManagement/updateUser', data)
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700129 .then(() => this.$router.push('/'))
130 .catch(() => (this.changePasswordError = true));
Derick Montague602e98a2020-10-21 16:20:00 -0500131 },
132 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700133};
134</script>
135
136<style lang="scss" scoped>
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700137@import '@/assets/styles/bmc/helpers/_index.scss';
138@import '@/assets/styles/bootstrap/_helpers.scss';
139
140@import '@/assets/styles/bootstrap/_helpers.scss';
141
Derick Montague932aff92021-08-26 14:06:49 -0500142.change-password__form-container {
143 @include media-breakpoint-up('md') {
144 max-width: 360px;
145 }
Yoshie Muranaka33058572020-06-16 13:21:21 -0700146}
147</style>