2020-09-12 19:02:12 +02:00
|
|
|
<template>
|
2020-09-27 22:36:32 +02:00
|
|
|
<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>
|
|
|
|
import api from '@/helpers/api'
|
2020-09-27 22:36:32 +02:00
|
|
|
import { PasswordForm } from '@/components/reusableForms'
|
2020-09-12 19:02:12 +02:00
|
|
|
import InputHelper from '@/components/InputHelper'
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'ToolAdminpw',
|
|
|
|
|
|
|
|
data () {
|
|
|
|
return {
|
2020-09-27 22:36:32 +02:00
|
|
|
currentPassword: '',
|
2020-09-12 19:02:12 +02:00
|
|
|
isValid: {
|
|
|
|
currentPassword: null,
|
|
|
|
password: null,
|
|
|
|
confirmation: null
|
|
|
|
},
|
|
|
|
error: {
|
2020-09-27 22:36:32 +02:00
|
|
|
currentPassword: '',
|
|
|
|
password: '',
|
|
|
|
confirmation: ''
|
2020-09-12 19:02:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-09-27 22:36:32 +02:00
|
|
|
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(() => {
|
2020-09-27 22:36:32 +02:00
|
|
|
this.$store.dispatch('DISCONNECT')
|
|
|
|
this.$router.push({ name: 'login' })
|
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')
|
2020-09-27 22:36:32 +02:00
|
|
|
this.isValid.currentPassword = this.currentPassword.length >= 8 ? null : false
|
2020-09-12 19:02:12 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
InputHelper,
|
2020-09-27 22:36:32 +02:00
|
|
|
PasswordForm
|
2020-09-12 19:02:12 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|