2020-09-12 19:02:12 +02:00
|
|
|
<template>
|
2020-09-27 22:36:32 +02:00
|
|
|
<password-form
|
2020-10-30 17:23:24 +01:00
|
|
|
:title="$t('postinstall_set_password')"
|
|
|
|
:server-error="serverError"
|
2020-09-27 22:36:32 +02:00
|
|
|
@submit="onSubmit"
|
2020-10-30 17:23:24 +01:00
|
|
|
:extra="extra"
|
2020-12-16 12:16:43 +01:00
|
|
|
/>
|
2020-09-12 19:02:12 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2020-10-12 17:36:47 +02:00
|
|
|
import api from '@/api'
|
2020-10-30 17:23:24 +01:00
|
|
|
import { validationMixin } from 'vuelidate'
|
|
|
|
|
2021-02-11 16:58:57 +01:00
|
|
|
import { PasswordForm } from '@/views/_partials'
|
2020-10-30 17:23:24 +01:00
|
|
|
import { required, minLength } from '@/helpers/validators'
|
|
|
|
|
2020-09-12 19:02:12 +02:00
|
|
|
export default {
|
|
|
|
name: 'ToolAdminpw',
|
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
2020-10-30 17:23:24 +01:00
|
|
|
serverError: '',
|
|
|
|
|
|
|
|
extra: {
|
|
|
|
form: {
|
|
|
|
currentPassword: ''
|
|
|
|
},
|
|
|
|
fields: {
|
|
|
|
currentPassword: {
|
|
|
|
label: this.$i18n.t('tools_adminpw_current'),
|
|
|
|
description: this.$i18n.t('tools_adminpw_current_placeholder'),
|
|
|
|
props: { id: 'current-password', type: 'password', placeholder: '••••••••' }
|
|
|
|
}
|
|
|
|
},
|
|
|
|
validations: {
|
|
|
|
currentPassword: { required, passwordLenght: minLength(8) }
|
|
|
|
}
|
2020-09-12 19:02:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-10-30 17:23:24 +01:00
|
|
|
onSubmit ({ password, currentPassword }) {
|
|
|
|
this.serverError = ''
|
|
|
|
// Use `api.fetch` to avoid automatic redirect on 401 (Unauthorized).
|
|
|
|
api.fetch('POST', 'login', { password: currentPassword }).then(response => {
|
|
|
|
if (response.status === 401) {
|
|
|
|
// Dispatch `SERVER_RESPONDED` to hide waiting overlay and display error.
|
|
|
|
this.$store.dispatch('SERVER_RESPONDED', true)
|
|
|
|
this.serverError = this.$i18n.t('wrong_password')
|
|
|
|
} else if (response.ok) {
|
|
|
|
api.put('adminpw', { new_password: password }).then(() => {
|
|
|
|
this.$store.dispatch('DISCONNECT')
|
|
|
|
}).catch(error => {
|
|
|
|
this.serverError = error.message
|
|
|
|
})
|
|
|
|
}
|
2020-09-12 19:02:12 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-10-30 17:23:24 +01:00
|
|
|
mixins: [validationMixin],
|
2020-12-16 12:16:43 +01:00
|
|
|
components: { PasswordForm }
|
2020-09-12 19:02:12 +02:00
|
|
|
}
|
|
|
|
</script>
|