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

73 lines
1.8 KiB
Vue
Raw Normal View History

2020-09-12 19:02:12 +02:00
<template>
<password-form
:title="$t('postinstall_set_password')" :submit-text="$t('next')"
:error="error" :is-valid="isValid"
@submit="onSubmit"
>
<template v-slot:input>
<!-- CURRENT ADMIN PASSWORD -->
<input-helper
id="current-password" type="password" :label="$t('tools_adminpw_current')"
v-model="currentPassword" :placeholder="$t('tools_adminpw_current_placeholder')"
:state="isValid.currentPassword" :error="error.currentPassword"
@input="validateCurrentPassword"
/>
<hr>
</template>
</password-form>
2020-09-12 19:02:12 +02:00
</template>
<script>
2020-10-12 17:36:47 +02:00
import api from '@/api'
import { PasswordForm } from '@/components/reusableForms'
2020-09-12 19:02:12 +02:00
import InputHelper from '@/components/InputHelper'
export default {
name: 'ToolAdminpw',
data () {
return {
currentPassword: '',
2020-09-12 19:02:12 +02:00
isValid: {
currentPassword: null,
password: null,
confirmation: null
},
error: {
currentPassword: '',
password: '',
confirmation: ''
2020-09-12 19:02:12 +02:00
}
}
},
methods: {
onSubmit (password) {
if (this.isValid.currentPassword === false) return
api.post('login', { password: this.currentPassword }).then(() => {
2020-09-12 19:02:12 +02:00
api.put('adminpw', { new_password: password }).then(() => {
this.$store.dispatch('DISCONNECT')
2020-09-12 19:02:12 +02:00
}).catch(err => {
this.error.password = err.message
this.isValid.password = false
})
}).catch(() => {
this.error.currentPassword = this.$i18n.t('wrong_password')
this.isValid.currentPassword = false
})
},
validateCurrentPassword () {
this.error.currentPassword = this.$i18n.t('passwords_too_short')
this.isValid.currentPassword = this.currentPassword.length >= 8 ? null : false
2020-09-12 19:02:12 +02:00
}
},
components: {
InputHelper,
PasswordForm
2020-09-12 19:02:12 +02:00
}
}
</script>