blob: 002362a9357133d2c65e216c215979a1d792a2f0 [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"
25 :state="getValidationState($v.form.password)"
26 class="form-control-with-button"
27 @change="$v.form.password.$touch()"
28 >
29 </b-form-input>
30 <b-form-invalid-feedback role="alert">
31 <template v-if="!$v.form.password.required">
32 {{ $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"
46 :state="getValidationState($v.form.passwordConfirm)"
47 class="form-control-with-button"
48 @change="$v.form.passwordConfirm.$touch()"
49 >
50 </b-form-input>
51 <b-form-invalid-feedback role="alert">
52 <template v-if="!$v.form.passwordConfirm.required">
53 {{ $t('global.form.fieldRequired') }}
54 </template>
55 <template v-else-if="!$v.form.passwordConfirm.sameAsPassword">
56 {{ $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 Tanous9c729792024-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 Tanous9c729792024-03-23 14:56:34 -070080import { useVuelidate } from '@vuelidate/core';
Yoshie Muranaka33058572020-06-16 13:21:21 -070081
82export default {
83 name: 'ChangePassword',
84 components: { Alert, InputPasswordToggle },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070085 mixins: [VuelidateMixin, BVToastMixin],
Ed Tanous9c729792024-03-23 14:56:34 -070086 setup() {
87 return {
88 v$: useVuelidate(),
89 };
90 },
Yoshie Muranaka33058572020-06-16 13:21:21 -070091 data() {
92 return {
93 form: {
94 password: null,
Derick Montague602e98a2020-10-21 16:20:00 -050095 passwordConfirm: null,
Yoshie Muranaka33058572020-06-16 13:21:21 -070096 },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070097 username: this.$store.getters['global/username'],
Derick Montague602e98a2020-10-21 16:20:00 -050098 changePasswordError: false,
Yoshie Muranaka33058572020-06-16 13:21:21 -070099 };
100 },
101 validations() {
102 return {
103 form: {
104 password: { required },
105 passwordConfirm: {
106 required,
Derick Montague602e98a2020-10-21 16:20:00 -0500107 sameAsPassword: sameAs('password'),
108 },
109 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700110 };
111 },
112 methods: {
113 goBack() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700114 // Remove session created if navigating back to the Login page
115 this.$store.dispatch('authentication/logout');
Yoshie Muranaka33058572020-06-16 13:21:21 -0700116 },
117 changePassword() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700118 this.$v.$touch();
119 if (this.$v.$invalid) return;
120 let data = {
121 originalUsername: this.username,
Derick Montague602e98a2020-10-21 16:20:00 -0500122 password: this.form.password,
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700123 };
124
125 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530126 .dispatch('userManagement/updateUser', data)
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700127 .then(() => this.$router.push('/'))
128 .catch(() => (this.changePasswordError = true));
Derick Montague602e98a2020-10-21 16:20:00 -0500129 },
130 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700131};
132</script>
133
134<style lang="scss" scoped>
Ed Tanous9c729792024-03-23 14:56:34 -0700135@import '@/assets/styles/bmc/helpers/_index.scss';
136@import '@/assets/styles/bootstrap/_helpers.scss';
137
138@import '@/assets/styles/bootstrap/_helpers.scss';
139
Derick Montague932aff92021-08-26 14:06:49 -0500140.change-password__form-container {
141 @include media-breakpoint-up('md') {
142 max-width: 360px;
143 }
Yoshie Muranaka33058572020-06-16 13:21:21 -0700144}
145</style>