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: {
|
2021-02-19 18:52:54 +01:00
|
|
|
onSubmit ({ currentPassword, password }) {
|
2020-10-30 17:23:24 +01:00
|
|
|
this.serverError = ''
|
2021-02-19 18:52:54 +01:00
|
|
|
|
|
|
|
api.fetchAll(
|
2021-04-09 21:47:19 +02:00
|
|
|
[['POST', 'login', { password: currentPassword }, null, { websocket: false }],
|
|
|
|
['PUT', 'adminpw', { new_password: password }, 'adminpw']],
|
2021-02-19 18:52:54 +01:00
|
|
|
{ wait: true }
|
|
|
|
).then(() => {
|
|
|
|
this.$store.dispatch('DISCONNECT')
|
|
|
|
}).catch(err => {
|
|
|
|
if (err.name === 'APIUnauthorizedError') {
|
|
|
|
// Prevent automatic disconnect if error in current password.
|
2020-10-30 17:23:24 +01:00
|
|
|
this.serverError = this.$i18n.t('wrong_password')
|
2021-02-19 18:52:54 +01:00
|
|
|
} else if (err.name === 'APIBadRequestError') {
|
|
|
|
// Display form error
|
|
|
|
this.serverError = err.message
|
|
|
|
} else {
|
|
|
|
throw err
|
2020-10-30 17:23:24 +01:00
|
|
|
}
|
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>
|