blob: fbf95d9d92519e3f89b34c193137e18294e7e9df [file] [log] [blame]
Yoshie Muranaka33058572020-06-16 13:21:21 -07001<template>
2 <div class="change-password-container mx-auto ml-md-5 mb-3">
3 <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>
9 <dl>
10 <dt>{{ $t('pageChangePassword.username') }}</dt>
11 <dd>{{ username }}</dd>
12 </dl>
13 <b-form novalidate @submit.prevent="changePassword">
14 <b-form-group
15 label-for="password"
16 :label="$t('pageChangePassword.newPassword')"
17 >
18 <input-password-toggle>
19 <b-form-input
20 id="password"
21 v-model="form.password"
22 autofocus="autofocus"
23 type="password"
24 :state="getValidationState($v.form.password)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -050025 class="form-control-with-button"
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070026 @change="$v.form.password.$touch()"
Yoshie Muranaka33058572020-06-16 13:21:21 -070027 >
28 </b-form-input>
29 <b-form-invalid-feedback role="alert">
30 <template v-if="!$v.form.password.required">
31 {{ $t('global.form.fieldRequired') }}
32 </template>
33 </b-form-invalid-feedback>
34 </input-password-toggle>
35 </b-form-group>
36 <b-form-group
37 label-for="password-confirm"
38 :label="$t('pageChangePassword.confirmNewPassword')"
39 >
40 <input-password-toggle>
41 <b-form-input
42 id="password-confirm"
43 v-model="form.passwordConfirm"
44 type="password"
45 :state="getValidationState($v.form.passwordConfirm)"
Dixsie Wolmers5ea16782020-07-27 17:50:43 -050046 class="form-control-with-button"
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070047 @change="$v.form.passwordConfirm.$touch()"
Yoshie Muranaka33058572020-06-16 13:21:21 -070048 >
49 </b-form-input>
50 <b-form-invalid-feedback role="alert">
51 <template v-if="!$v.form.passwordConfirm.required">
52 {{ $t('global.form.fieldRequired') }}
53 </template>
54 <template v-else-if="!$v.form.passwordConfirm.sameAsPassword">
55 {{ $t('global.form.passwordsDoNotMatch') }}
56 </template>
57 </b-form-invalid-feedback>
58 </input-password-toggle>
59 </b-form-group>
60 <div class="text-right">
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070061 <b-button type="button" variant="link" @click="goBack">
Yoshie Muranaka33058572020-06-16 13:21:21 -070062 {{ $t('pageChangePassword.goBack') }}
63 </b-button>
64 <b-button type="submit" variant="primary">
65 {{ $t('pageChangePassword.changePassword') }}
66 </b-button>
67 </div>
68 </b-form>
69 </div>
70</template>
71
72<script>
73import { required, sameAs } from 'vuelidate/lib/validators';
74import Alert from '@/components/Global/Alert';
75import VuelidateMixin from '@/components/Mixins/VuelidateMixin';
76import InputPasswordToggle from '@/components/Global/InputPasswordToggle';
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070077import BVToastMixin from '@/components/Mixins/BVToastMixin';
Yoshie Muranaka33058572020-06-16 13:21:21 -070078
79export default {
80 name: 'ChangePassword',
81 components: { Alert, InputPasswordToggle },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070082 mixins: [VuelidateMixin, BVToastMixin],
Yoshie Muranaka33058572020-06-16 13:21:21 -070083 data() {
84 return {
85 form: {
86 password: null,
87 passwordConfirm: null
88 },
Yoshie Muranaka2c98b092020-06-22 13:28:09 -070089 username: this.$store.getters['global/username'],
90 changePasswordError: false
Yoshie Muranaka33058572020-06-16 13:21:21 -070091 };
92 },
93 validations() {
94 return {
95 form: {
96 password: { required },
97 passwordConfirm: {
98 required,
99 sameAsPassword: sameAs('password')
100 }
101 }
102 };
103 },
104 methods: {
105 goBack() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700106 // Remove session created if navigating back to the Login page
107 this.$store.dispatch('authentication/logout');
Yoshie Muranaka33058572020-06-16 13:21:21 -0700108 },
109 changePassword() {
Yoshie Muranaka2c98b092020-06-22 13:28:09 -0700110 this.$v.$touch();
111 if (this.$v.$invalid) return;
112 let data = {
113 originalUsername: this.username,
114 password: this.form.password
115 };
116
117 this.$store
118 .dispatch('localUsers/updateUser', data)
119 .then(() => this.$router.push('/'))
120 .catch(() => (this.changePasswordError = true));
Yoshie Muranaka33058572020-06-16 13:21:21 -0700121 }
122 }
123};
124</script>
125
126<style lang="scss" scoped>
127.change-password-container {
128 max-width: 360px;
129}
130</style>