yunohost-admin/app/src/views/tool/ToolAdminpw.vue

70 lines
1.7 KiB
Vue
Raw Normal View History

2020-09-12 19:02:12 +02:00
<template>
<password-form
:title="$t('postinstall_set_password')"
:server-error="serverError"
@submit="onSubmit"
:extra="extra"
/>
2020-09-12 19:02:12 +02:00
</template>
<script>
2020-10-12 17:36:47 +02:00
import api from '@/api'
import { validationMixin } from 'vuelidate'
import { PasswordForm } from '@/views/_partials'
import { required, minLength } from '@/helpers/validators'
2020-09-12 19:02:12 +02:00
export default {
name: 'ToolAdminpw',
data () {
return {
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 }) {
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.
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-09-12 19:02:12 +02:00
})
}
},
mixins: [validationMixin],
components: { PasswordForm }
2020-09-12 19:02:12 +02:00
}
</script>