133058576SYoshie Muranaka<template> 2*932aff93SDerick Montague <div class="change-password-container"> 333058576SYoshie Muranaka <alert variant="danger" class="mb-4"> 42c98b095SYoshie Muranaka <p v-if="changePasswordError"> 52c98b095SYoshie Muranaka {{ $t('pageChangePassword.changePasswordError') }} 62c98b095SYoshie Muranaka </p> 72c98b095SYoshie Muranaka <p v-else>{{ $t('pageChangePassword.changePasswordAlertMessage') }}</p> 833058576SYoshie Muranaka </alert> 9*932aff93SDerick Montague <div class="change-password__form-container"> 1033058576SYoshie Muranaka <dl> 1133058576SYoshie Muranaka <dt>{{ $t('pageChangePassword.username') }}</dt> 1233058576SYoshie Muranaka <dd>{{ username }}</dd> 1333058576SYoshie Muranaka </dl> 1433058576SYoshie Muranaka <b-form novalidate @submit.prevent="changePassword"> 1533058576SYoshie Muranaka <b-form-group 1633058576SYoshie Muranaka label-for="password" 1733058576SYoshie Muranaka :label="$t('pageChangePassword.newPassword')" 1833058576SYoshie Muranaka > 1933058576SYoshie Muranaka <input-password-toggle> 2033058576SYoshie Muranaka <b-form-input 2133058576SYoshie Muranaka id="password" 2233058576SYoshie Muranaka v-model="form.password" 2333058576SYoshie Muranaka autofocus="autofocus" 2433058576SYoshie Muranaka type="password" 2533058576SYoshie Muranaka :state="getValidationState($v.form.password)" 265ea16782SDixsie Wolmers class="form-control-with-button" 272c98b095SYoshie Muranaka @change="$v.form.password.$touch()" 2833058576SYoshie Muranaka > 2933058576SYoshie Muranaka </b-form-input> 3033058576SYoshie Muranaka <b-form-invalid-feedback role="alert"> 3133058576SYoshie Muranaka <template v-if="!$v.form.password.required"> 3233058576SYoshie Muranaka {{ $t('global.form.fieldRequired') }} 3333058576SYoshie Muranaka </template> 3433058576SYoshie Muranaka </b-form-invalid-feedback> 3533058576SYoshie Muranaka </input-password-toggle> 3633058576SYoshie Muranaka </b-form-group> 3733058576SYoshie Muranaka <b-form-group 3833058576SYoshie Muranaka label-for="password-confirm" 3933058576SYoshie Muranaka :label="$t('pageChangePassword.confirmNewPassword')" 4033058576SYoshie Muranaka > 4133058576SYoshie Muranaka <input-password-toggle> 4233058576SYoshie Muranaka <b-form-input 4333058576SYoshie Muranaka id="password-confirm" 4433058576SYoshie Muranaka v-model="form.passwordConfirm" 4533058576SYoshie Muranaka type="password" 4633058576SYoshie Muranaka :state="getValidationState($v.form.passwordConfirm)" 475ea16782SDixsie Wolmers class="form-control-with-button" 482c98b095SYoshie Muranaka @change="$v.form.passwordConfirm.$touch()" 4933058576SYoshie Muranaka > 5033058576SYoshie Muranaka </b-form-input> 5133058576SYoshie Muranaka <b-form-invalid-feedback role="alert"> 5233058576SYoshie Muranaka <template v-if="!$v.form.passwordConfirm.required"> 5333058576SYoshie Muranaka {{ $t('global.form.fieldRequired') }} 5433058576SYoshie Muranaka </template> 5533058576SYoshie Muranaka <template v-else-if="!$v.form.passwordConfirm.sameAsPassword"> 5633058576SYoshie Muranaka {{ $t('global.form.passwordsDoNotMatch') }} 5733058576SYoshie Muranaka </template> 5833058576SYoshie Muranaka </b-form-invalid-feedback> 5933058576SYoshie Muranaka </input-password-toggle> 6033058576SYoshie Muranaka </b-form-group> 6133058576SYoshie Muranaka <div class="text-right"> 622c98b095SYoshie Muranaka <b-button type="button" variant="link" @click="goBack"> 6333058576SYoshie Muranaka {{ $t('pageChangePassword.goBack') }} 6433058576SYoshie Muranaka </b-button> 6533058576SYoshie Muranaka <b-button type="submit" variant="primary"> 6633058576SYoshie Muranaka {{ $t('pageChangePassword.changePassword') }} 6733058576SYoshie Muranaka </b-button> 6833058576SYoshie Muranaka </div> 6933058576SYoshie Muranaka </b-form> 7033058576SYoshie Muranaka </div> 71*932aff93SDerick Montague </div> 7233058576SYoshie Muranaka</template> 7333058576SYoshie Muranaka 7433058576SYoshie Muranaka<script> 7533058576SYoshie Muranakaimport { required, sameAs } from 'vuelidate/lib/validators'; 7633058576SYoshie Muranakaimport Alert from '@/components/Global/Alert'; 7733058576SYoshie Muranakaimport VuelidateMixin from '@/components/Mixins/VuelidateMixin'; 7833058576SYoshie Muranakaimport InputPasswordToggle from '@/components/Global/InputPasswordToggle'; 792c98b095SYoshie Muranakaimport BVToastMixin from '@/components/Mixins/BVToastMixin'; 8033058576SYoshie Muranaka 8133058576SYoshie Muranakaexport default { 8233058576SYoshie Muranaka name: 'ChangePassword', 8333058576SYoshie Muranaka components: { Alert, InputPasswordToggle }, 842c98b095SYoshie Muranaka mixins: [VuelidateMixin, BVToastMixin], 8533058576SYoshie Muranaka data() { 8633058576SYoshie Muranaka return { 8733058576SYoshie Muranaka form: { 8833058576SYoshie Muranaka password: null, 89602e98aaSDerick Montague passwordConfirm: null, 9033058576SYoshie Muranaka }, 912c98b095SYoshie Muranaka username: this.$store.getters['global/username'], 92602e98aaSDerick Montague changePasswordError: false, 9333058576SYoshie Muranaka }; 9433058576SYoshie Muranaka }, 9533058576SYoshie Muranaka validations() { 9633058576SYoshie Muranaka return { 9733058576SYoshie Muranaka form: { 9833058576SYoshie Muranaka password: { required }, 9933058576SYoshie Muranaka passwordConfirm: { 10033058576SYoshie Muranaka required, 101602e98aaSDerick Montague sameAsPassword: sameAs('password'), 102602e98aaSDerick Montague }, 103602e98aaSDerick Montague }, 10433058576SYoshie Muranaka }; 10533058576SYoshie Muranaka }, 10633058576SYoshie Muranaka methods: { 10733058576SYoshie Muranaka goBack() { 1082c98b095SYoshie Muranaka // Remove session created if navigating back to the Login page 1092c98b095SYoshie Muranaka this.$store.dispatch('authentication/logout'); 11033058576SYoshie Muranaka }, 11133058576SYoshie Muranaka changePassword() { 1122c98b095SYoshie Muranaka this.$v.$touch(); 1132c98b095SYoshie Muranaka if (this.$v.$invalid) return; 1142c98b095SYoshie Muranaka let data = { 1152c98b095SYoshie Muranaka originalUsername: this.username, 116602e98aaSDerick Montague password: this.form.password, 1172c98b095SYoshie Muranaka }; 1182c98b095SYoshie Muranaka 1192c98b095SYoshie Muranaka this.$store 120b440616cSSandeepa Singh .dispatch('userManagement/updateUser', data) 1212c98b095SYoshie Muranaka .then(() => this.$router.push('/')) 1222c98b095SYoshie Muranaka .catch(() => (this.changePasswordError = true)); 123602e98aaSDerick Montague }, 124602e98aaSDerick Montague }, 12533058576SYoshie Muranaka}; 12633058576SYoshie Muranaka</script> 12733058576SYoshie Muranaka 12833058576SYoshie Muranaka<style lang="scss" scoped> 129*932aff93SDerick Montague.change-password__form-container { 130*932aff93SDerick Montague @include media-breakpoint-up('md') { 13133058576SYoshie Muranaka max-width: 360px; 13233058576SYoshie Muranaka } 133*932aff93SDerick Montague} 13433058576SYoshie Muranaka</style> 135