|
| 1 | +import Vue from 'vue'; |
| 2 | +import { isObject } from 'lodash'; |
| 3 | +import {AxiosError} from "axios"; |
| 4 | + |
| 5 | +export default Vue.component('change-password', { |
| 6 | + data: function () { |
| 7 | + return { |
| 8 | + current: '', |
| 9 | + newPassword: '', |
| 10 | + confirmNew: '', |
| 11 | + }; |
| 12 | + }, |
| 13 | + |
| 14 | + methods: { |
| 15 | + submitForm: function () { |
| 16 | + this.$flash.clear(); |
| 17 | + this.$validator.pause(); |
| 18 | + |
| 19 | + window.axios.put(this.route('api.client.account.update-password'), { |
| 20 | + current_password: this.current, |
| 21 | + password: this.newPassword, |
| 22 | + password_confirmation: this.confirmNew, |
| 23 | + }) |
| 24 | + .then(() => this.current = '') |
| 25 | + .then(() => { |
| 26 | + this.newPassword = ''; |
| 27 | + this.confirmNew = ''; |
| 28 | + |
| 29 | + this.$flash.success(this.$t('dashboard.account.password.updated')); |
| 30 | + }) |
| 31 | + .catch((err: AxiosError) => { |
| 32 | + if (!err.response) { |
| 33 | + this.$flash.error('There was an error with the network request. Please try again.'); |
| 34 | + console.error(err); |
| 35 | + return; |
| 36 | + } |
| 37 | + |
| 38 | + const response = err.response; |
| 39 | + if (response.data && isObject(response.data.errors)) { |
| 40 | + response.data.errors.forEach((error: any) => { |
| 41 | + this.$flash.error(error.detail); |
| 42 | + }); |
| 43 | + } |
| 44 | + }) |
| 45 | + .then(() => { |
| 46 | + this.$validator.resume(); |
| 47 | + (this.$refs.current as HTMLElement).focus(); |
| 48 | + }) |
| 49 | + } |
| 50 | + }, |
| 51 | + |
| 52 | + template: ` |
| 53 | + <div id="change-password-container" :class> |
| 54 | + <form method="post" v-on:submit.prevent="submitForm"> |
| 55 | + <div class="content-box"> |
| 56 | + <h2 class="mb-6 text-grey-darkest font-medium">{{ $t('dashboard.account.password.title') }}</h2> |
| 57 | + <div class="mt-6"> |
| 58 | + <label for="grid-password-current" class="input-label">{{ $t('strings.password') }}</label> |
| 59 | + <input id="grid-password-current" name="current_password" type="password" class="input" required |
| 60 | + ref="current" |
| 61 | + v-model="current" |
| 62 | + > |
| 63 | + </div> |
| 64 | + <div class="mt-6"> |
| 65 | + <label for="grid-password-new" class="input-label">{{ $t('strings.new_password') }}</label> |
| 66 | + <input id="grid-password-new" name="password" type="password" class="input" required |
| 67 | + :class="{ error: errors.has('password') }" |
| 68 | + v-model="newPassword" |
| 69 | + v-validate="'min:8'" |
| 70 | + > |
| 71 | + <p class="input-help error" v-show="errors.has('password')">{{ errors.first('password') }}</p> |
| 72 | + <p class="input-help">{{ $t('dashboard.account.password.requirements') }}</p> |
| 73 | + </div> |
| 74 | + <div class="mt-6"> |
| 75 | + <label for="grid-password-new-confirm" class="input-label">{{ $t('strings.confirm_password') }}</label> |
| 76 | + <input id="grid-password-new-confirm" name="password_confirmation" type="password" class="input" required |
| 77 | + :class="{ error: errors.has('password_confirmation') }" |
| 78 | + v-model="confirmNew" |
| 79 | + v-validate="{is: newPassword}" |
| 80 | + data-vv-as="password" |
| 81 | + > |
| 82 | + <p class="input-help error" v-show="errors.has('password_confirmation')">{{ errors.first('password_confirmation') }}</p> |
| 83 | + </div> |
| 84 | + <div class="mt-6 text-right"> |
| 85 | + <button class="btn btn-blue btn-sm text-right" type="submit">{{ $t('strings.save') }}</button> |
| 86 | + </div> |
| 87 | + </div> |
| 88 | + </form> |
| 89 | + </div> |
| 90 | + `, |
| 91 | +}); |
0 commit comments