blob: 2440ace1c20035b9ba0a7450ccd4782e14c9dba7 [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>
75import { required, sameAs } from 'vuelidate/lib/validators';
76import 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';
Yoshie Muranaka33058572020-06-16 13:21:21 -070080
81export default {
82 name: 'ChangePassword',
83 components: { Alert, InputPasswordToggle },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070084 mixins: [VuelidateMixin, BVToastMixin],
Yoshie Muranaka33058572020-06-16 13:21:21 -070085 data() {
86 return {
87 form: {
88 password: null,
Derick Montague602e98a2020-10-21 16:20:00 -050089 passwordConfirm: null,
Yoshie Muranaka33058572020-06-16 13:21:21 -070090 },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070091 username: this.$store.getters['global/username'],
Derick Montague602e98a2020-10-21 16:20:00 -050092 changePasswordError: false,
Yoshie Muranaka33058572020-06-16 13:21:21 -070093 };
94 },
95 validations() {
96 return {
97 form: {
98 password: { required },
99 passwordConfirm: {
100 required,
Derick Montague602e98a2020-10-21 16:20:00 -0500101 sameAsPassword: sameAs('password'),
102 },
103 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700104 };
105 },
106 methods: {
107 goBack() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700108 // Remove session created if navigating back to the Login page
109 this.$store.dispatch('authentication/logout');
Yoshie Muranaka33058572020-06-16 13:21:21 -0700110 },
111 changePassword() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700112 this.$v.$touch();
113 if (this.$v.$invalid) return;
114 let data = {
115 originalUsername: this.username,
Derick Montague602e98a2020-10-21 16:20:00 -0500116 password: this.form.password,
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700117 };
118
119 this.$store
Sandeepa Singhb4406162021-07-26 15:05:39 +0530120 .dispatch('userManagement/updateUser', data)
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700121 .then(() => this.$router.push('/'))
122 .catch(() => (this.changePasswordError = true));
Derick Montague602e98a2020-10-21 16:20:00 -0500123 },
124 },
Yoshie Muranaka33058572020-06-16 13:21:21 -0700125};
126</script>
127
128<style lang="scss" scoped>
Derick Montague932aff92021-08-26 14:06:49 -0500129.change-password__form-container {
130 @include media-breakpoint-up('md') {
131 max-width: 360px;
132 }
Yoshie Muranaka33058572020-06-16 13:21:21 -0700133}
134</style>