mirror of
https://github.com/YunoHost/yunohost-admin.git
synced 2024-09-03 20:06:15 +02:00
add customizable password and domain component to be used in multiples views
This commit is contained in:
parent
7710e6a1c3
commit
2df02ae39e
6 changed files with 357 additions and 195 deletions
191
app/src/components/reusableForms/DomainForm.vue
Normal file
191
app/src/components/reusableForms/DomainForm.vue
Normal file
|
@ -0,0 +1,191 @@
|
||||||
|
<template>
|
||||||
|
<b-card header-tag="h2" class="basic-form">
|
||||||
|
<template v-slot:header>
|
||||||
|
<h2><icon iname="globe" /> {{ title }}</h2>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<b-form id="domain-form" @submit.prevent="onSubmit">
|
||||||
|
<slot name="message" />
|
||||||
|
|
||||||
|
<!-- DOMAIN -->
|
||||||
|
<b-form-radio
|
||||||
|
v-model="selected" name="domain-type" value="domain"
|
||||||
|
:class="domainIsVisible ? null : 'collapsed'"
|
||||||
|
:aria-expanded="domainIsVisible ? 'true' : 'false'"
|
||||||
|
aria-controls="collapse-domain"
|
||||||
|
>
|
||||||
|
{{ $t('domain_add_panel_with_domain') }}
|
||||||
|
</b-form-radio>
|
||||||
|
|
||||||
|
<b-collapse id="collapse-domain" :visible.sync="domainIsVisible">
|
||||||
|
<small v-html="$t('domain_add_dns_doc')" />
|
||||||
|
|
||||||
|
<b-form-group
|
||||||
|
label-cols="auto" class="mt-2"
|
||||||
|
:label="$t('domain_name')" label-for="input-domain" label-tag="strong"
|
||||||
|
>
|
||||||
|
<b-input
|
||||||
|
id="input-domain" :placeholder="$t('placeholder.domain')"
|
||||||
|
aria-describedby="domain-feedback"
|
||||||
|
v-model="form.domain" :state="isValid.domain"
|
||||||
|
@input="validateDomainName($event)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<b-form-invalid-feedback id="domain-feedback" :state="isValid.domain">
|
||||||
|
{{ this.error.domain }}
|
||||||
|
</b-form-invalid-feedback>
|
||||||
|
</b-form-group>
|
||||||
|
</b-collapse>
|
||||||
|
|
||||||
|
<!-- DYN DOMAIN -->
|
||||||
|
<b-form-radio
|
||||||
|
v-model="selected" name="domain-type" value="dynDomain"
|
||||||
|
:disabled="dynDnsForbiden"
|
||||||
|
:class="dynDomainIsVisible ? null : 'collapsed'"
|
||||||
|
:aria-expanded="dynDomainIsVisible ? 'true' : 'false'"
|
||||||
|
aria-controls="collapse-dynDomain"
|
||||||
|
>
|
||||||
|
{{ $t('domain_add_panel_without_domain') }}
|
||||||
|
</b-form-radio>
|
||||||
|
|
||||||
|
<b-collapse id="collapse-dynDomain" :visible.sync="dynDomainIsVisible">
|
||||||
|
<small>{{ $t('domain_add_dyndns_doc') }}</small>
|
||||||
|
|
||||||
|
<b-form-group
|
||||||
|
label-cols="auto" class="mt-2"
|
||||||
|
:label="$t('domain_name')" label-for="input-dynDomain"
|
||||||
|
>
|
||||||
|
<adress-input-select
|
||||||
|
id="input-dynDomain" feedback-id="dynDomain-feedback"
|
||||||
|
v-model="form.dynDomain" :options="dynDomains"
|
||||||
|
:state="isValid.dynDomain" :placeholder="$t('myserver')"
|
||||||
|
separator="."
|
||||||
|
@input="validateDomainName($event)"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<b-form-invalid-feedback id="dynDomain-feedback" :state="isValid.dynDomain">
|
||||||
|
{{ this.error.dynDomain }}
|
||||||
|
</b-form-invalid-feedback>
|
||||||
|
</b-form-group>
|
||||||
|
</b-collapse>
|
||||||
|
</b-form>
|
||||||
|
|
||||||
|
<template v-slot:footer>
|
||||||
|
<b-button
|
||||||
|
type="submit" form="domain-form" variant="success"
|
||||||
|
:disabled="!everythingValid"
|
||||||
|
>
|
||||||
|
{{ submitText ? submitText : $t('add') }}
|
||||||
|
</b-button>
|
||||||
|
</template>
|
||||||
|
</b-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import AdressInputSelect from '@/components/AdressInputSelect'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'DomainForm',
|
||||||
|
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
submitText: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
isValid: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({
|
||||||
|
domainname: undefined,
|
||||||
|
dynDomainname: undefined
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({
|
||||||
|
domain: '',
|
||||||
|
dynDomain: ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
selected: '',
|
||||||
|
dynDomains: ['nohost.me', 'noho.st', 'ynh.fr'],
|
||||||
|
form: {
|
||||||
|
domain: '',
|
||||||
|
dynDomain: ['', 'nohost.me']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
domains () {
|
||||||
|
return this.$store.state.data.domains
|
||||||
|
},
|
||||||
|
|
||||||
|
dynDnsForbiden () {
|
||||||
|
if (!this.domains) return true
|
||||||
|
return this.domains.some(domain => {
|
||||||
|
return this.dynDomains.some(dynDomain => domain.includes(dynDomain))
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
domainIsVisible () {
|
||||||
|
return this.selected === 'domain'
|
||||||
|
},
|
||||||
|
|
||||||
|
dynDomainIsVisible () {
|
||||||
|
return this.selected === 'dynDomain'
|
||||||
|
},
|
||||||
|
|
||||||
|
everythingValid () {
|
||||||
|
const domain = this.form[this.selected]
|
||||||
|
if (!domain || !domain[0]) return false
|
||||||
|
this.validateDomainName(domain)
|
||||||
|
return this.isValid[this.selected] !== false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
onSubmit () {
|
||||||
|
if (!this.everythingValid) return
|
||||||
|
|
||||||
|
const domainType = this.selected
|
||||||
|
const domain = this.form[domainType]
|
||||||
|
this.$emit('submit', {
|
||||||
|
domain: domainType === 'dynDomain' ? domain.join('.') : domain,
|
||||||
|
domainType
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
validateDomainName (name) {
|
||||||
|
const domainType = this.selected
|
||||||
|
const domainname = domainType === 'domain' ? name : name[0]
|
||||||
|
const regex = domainType === 'domain' ? '^[.a-z0-9-]+$' : '^[a-z0-9-]+$'
|
||||||
|
let error = ''
|
||||||
|
if (!domainname.match(regex) || (domainType === 'domain' ? !domainname.includes('.') : false)) {
|
||||||
|
error = this.$i18n.t(`form_errors.${domainType}_syntax`)
|
||||||
|
}
|
||||||
|
this.error[this.selected] = error
|
||||||
|
this.isValid[this.selected] = error === '' ? null : false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
created () {
|
||||||
|
this.$store.dispatch('FETCH', { uri: 'domains' }).then(() => {
|
||||||
|
if (this.dynDnsForbiden) {
|
||||||
|
this.selected = 'domain'
|
||||||
|
}
|
||||||
|
})
|
||||||
|
},
|
||||||
|
|
||||||
|
components: {
|
||||||
|
AdressInputSelect
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
119
app/src/components/reusableForms/PasswordForm.vue
Normal file
119
app/src/components/reusableForms/PasswordForm.vue
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
<template>
|
||||||
|
<b-card header-tag="h2" class="basic-form">
|
||||||
|
<template v-slot:header>
|
||||||
|
<h2><icon iname="key-modern" /> {{ title }}</h2>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<b-form id="password-form" @submit.prevent="onSubmit">
|
||||||
|
<b-alert variant="warning" show>
|
||||||
|
{{ $t('good_practices_about_admin_password') }}
|
||||||
|
</b-alert>
|
||||||
|
|
||||||
|
<slot name="message" />
|
||||||
|
|
||||||
|
<hr>
|
||||||
|
|
||||||
|
<slot name="input" />
|
||||||
|
|
||||||
|
<!-- PASSWORD -->
|
||||||
|
<input-helper
|
||||||
|
id="password" type="password" :label="$t('password_new')"
|
||||||
|
v-model="form.password" :placeholder="$t('tools_adminpw_new_placeholder')"
|
||||||
|
:state="isValid.password" :error="error.password"
|
||||||
|
@input="validateNewPassword"
|
||||||
|
/>
|
||||||
|
|
||||||
|
<!-- PASSWORD CONFIRMATION -->
|
||||||
|
<input-helper
|
||||||
|
id="confirmation" type="password" :label="$t('password_confirmation')"
|
||||||
|
v-model="form.confirmation" :placeholder="$t('tools_adminpw_confirm_placeholder')"
|
||||||
|
:state="isValid.confirmation" :error="$t('passwords_dont_match')"
|
||||||
|
@input="validateNewPassword"
|
||||||
|
/>
|
||||||
|
</b-form>
|
||||||
|
|
||||||
|
<template v-slot:footer>
|
||||||
|
<b-button
|
||||||
|
type="submit" form="password-form" variant="success"
|
||||||
|
:disabled="!everythingValid"
|
||||||
|
>
|
||||||
|
{{ submitText ? submitText : $t('save') }}
|
||||||
|
</b-button>
|
||||||
|
</template>
|
||||||
|
</b-card>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
import InputHelper from '@/components/InputHelper'
|
||||||
|
|
||||||
|
export default {
|
||||||
|
name: 'PasswordForm',
|
||||||
|
|
||||||
|
props: {
|
||||||
|
title: {
|
||||||
|
type: String,
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
submitText: {
|
||||||
|
type: String,
|
||||||
|
default: null
|
||||||
|
},
|
||||||
|
isValid: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({
|
||||||
|
password: null,
|
||||||
|
confirmation: null
|
||||||
|
})
|
||||||
|
},
|
||||||
|
error: {
|
||||||
|
type: Object,
|
||||||
|
default: () => ({
|
||||||
|
password: '',
|
||||||
|
confirmation: ''
|
||||||
|
})
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
data () {
|
||||||
|
return {
|
||||||
|
form: {
|
||||||
|
password: '',
|
||||||
|
confirmation: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
everythingValid () {
|
||||||
|
for (const key in this.isValid) {
|
||||||
|
if (this.form[key] === '') return false
|
||||||
|
if (this.isValid[key] === false) return false
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
onSubmit () {
|
||||||
|
if (this.everythingValid) {
|
||||||
|
this.$emit('submit', this.form.password)
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
isValidPassword (password) {
|
||||||
|
return password.length >= 8 ? null : false
|
||||||
|
},
|
||||||
|
|
||||||
|
validateNewPassword () {
|
||||||
|
const { password, confirmation } = this.form
|
||||||
|
this.error.password = this.$i18n.t('passwords_too_short')
|
||||||
|
this.isValid.password = this.isValidPassword(password)
|
||||||
|
this.isValid.confirmation = password === confirmation ? null : false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
components: {
|
||||||
|
InputHelper
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
2
app/src/components/reusableForms/index.js
Normal file
2
app/src/components/reusableForms/index.js
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
export { default as PasswordForm } from './PasswordForm'
|
||||||
|
export { default as DomainForm } from './DomainForm'
|
|
@ -37,8 +37,8 @@ export default {
|
||||||
'DISCONNECT' ({ commit }, route) {
|
'DISCONNECT' ({ commit }, route) {
|
||||||
commit('SET_CONNECTED', false)
|
commit('SET_CONNECTED', false)
|
||||||
commit('SET_YUNOHOST_INFOS', null)
|
commit('SET_YUNOHOST_INFOS', null)
|
||||||
// Do not redirect if the current route is `login` so the view can display an error.
|
// Do not redirect if the current route needs to display an error.
|
||||||
if (router.currentRoute.name === 'login') return
|
if (['login', 'tool-adminpw'].includes(router.currentRoute.name)) return
|
||||||
router.push({
|
router.push({
|
||||||
name: 'login',
|
name: 'login',
|
||||||
// Add a redirect query if next route is not unknown (like `logout`) or `login`
|
// Add a redirect query if next route is not unknown (like `logout`) or `login`
|
||||||
|
@ -63,6 +63,7 @@ export default {
|
||||||
'CHECK_INSTALL' ({ dispatch }, retry = 2) {
|
'CHECK_INSTALL' ({ dispatch }, retry = 2) {
|
||||||
// this action will try to query the `/installed` route 3 times every 5 s with
|
// this action will try to query the `/installed` route 3 times every 5 s with
|
||||||
// a timeout of the same delay.
|
// a timeout of the same delay.
|
||||||
|
// FIXME need testing with api not responding
|
||||||
return timeout(api.get('installed'), 5000).then(({ installed }) => {
|
return timeout(api.get('installed'), 5000).then(({ installed }) => {
|
||||||
return installed
|
return installed
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
|
|
|
@ -1,90 +1,22 @@
|
||||||
<template lang="html">
|
<template lang="html">
|
||||||
<basic-form
|
<domain-form
|
||||||
:header="$t('domain_add')" :submit="$t('add')"
|
:title="$t('domain_add')"
|
||||||
@submit.prevent="onSubmit"
|
:error="error" :is-valid="isValid"
|
||||||
>
|
@submit="onSubmit"
|
||||||
<!-- DOMAIN -->
|
/>
|
||||||
<b-form-radio
|
|
||||||
v-model="selected" name="domain-type" value="domain"
|
|
||||||
:class="domainIsVisible ? null : 'collapsed'"
|
|
||||||
:aria-expanded="domainIsVisible ? 'true' : 'false'"
|
|
||||||
aria-controls="collapse-domain"
|
|
||||||
>
|
|
||||||
{{ $t('domain_add_panel_with_domain') }}
|
|
||||||
</b-form-radio>
|
|
||||||
|
|
||||||
<b-collapse id="collapse-domain" :visible.sync="domainIsVisible">
|
|
||||||
<small v-html="$t('domain_add_dns_doc')" />
|
|
||||||
|
|
||||||
<b-form-group
|
|
||||||
label-cols="auto"
|
|
||||||
:label="$t('domain_name')" label-for="input-domain" label-tag="strong"
|
|
||||||
>
|
|
||||||
<b-input
|
|
||||||
id="input-domain" :placeholder="$t('placeholder.domain')"
|
|
||||||
aria-describedby="domain-feedback"
|
|
||||||
v-model="form.domain" :state="isValid.domain"
|
|
||||||
@input="validateDomainName($event)"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<b-form-invalid-feedback id="domain-feedback" :state="isValid.domain">
|
|
||||||
{{ this.error.domain }}
|
|
||||||
</b-form-invalid-feedback>
|
|
||||||
</b-form-group>
|
|
||||||
</b-collapse>
|
|
||||||
|
|
||||||
<!-- DYN DOMAIN -->
|
|
||||||
<b-form-radio
|
|
||||||
v-model="selected" name="domain-type" value="dynDomain"
|
|
||||||
:disabled="dynDnsForbiden"
|
|
||||||
:class="dynDomainIsVisible ? null : 'collapsed'"
|
|
||||||
:aria-expanded="dynDomainIsVisible ? 'true' : 'false'"
|
|
||||||
aria-controls="collapse-dynDomain"
|
|
||||||
>
|
|
||||||
{{ $t('domain_add_panel_without_domain') }}
|
|
||||||
</b-form-radio>
|
|
||||||
|
|
||||||
<b-collapse id="collapse-dynDomain" :visible.sync="dynDomainIsVisible">
|
|
||||||
<small>{{ $t('domain_add_dyndns_doc') }}</small>
|
|
||||||
|
|
||||||
<b-form-group
|
|
||||||
label-cols="auto"
|
|
||||||
:label="$t('domain_name')" label-for="input-dynDomain"
|
|
||||||
>
|
|
||||||
<adress-input-select
|
|
||||||
id="input-dynDomain" feedback-id="dynDomain-feedback"
|
|
||||||
v-model="form.dynDomain" :options="dynDomains"
|
|
||||||
:state="isValid.dynDomain" :placeholder="$t('myserver')"
|
|
||||||
separator="."
|
|
||||||
@input="validateDomainName($event)"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<b-form-invalid-feedback id="dynDomain-feedback" :state="isValid.dynDomain">
|
|
||||||
{{ this.error.dynDomain }}
|
|
||||||
</b-form-invalid-feedback>
|
|
||||||
</b-form-group>
|
|
||||||
</b-collapse>
|
|
||||||
</basic-form>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import BasicForm from '@/components/BasicForm'
|
import { DomainForm } from '@/components/reusableForms'
|
||||||
import AdressInputSelect from '@/components/AdressInputSelect'
|
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: 'DomainAdd',
|
name: 'DomainAdd',
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
selected: '',
|
|
||||||
dynDomains: ['nohost.me', 'noho.st', 'ynh.fr'],
|
|
||||||
form: {
|
|
||||||
domain: '',
|
|
||||||
dynDomain: ['', 'nohost.me']
|
|
||||||
},
|
|
||||||
isValid: {
|
isValid: {
|
||||||
domainname: null,
|
domainname: undefined,
|
||||||
dynDomainname: null
|
dynDomainname: undefined
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
domain: '',
|
domain: '',
|
||||||
|
@ -93,77 +25,25 @@ export default {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
|
||||||
domains () {
|
|
||||||
return this.$store.state.data.domains
|
|
||||||
},
|
|
||||||
|
|
||||||
dynDnsForbiden () {
|
|
||||||
if (!this.domains) return true
|
|
||||||
return this.domains.some(domain => {
|
|
||||||
return this.dynDomains.some(dynDomain => domain.includes(dynDomain))
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
domainIsVisible () {
|
|
||||||
return this.selected === 'domain'
|
|
||||||
},
|
|
||||||
|
|
||||||
dynDomainIsVisible () {
|
|
||||||
return this.selected === 'dynDomain'
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onSubmit () {
|
onSubmit ({ domain, domainType }) {
|
||||||
const domainType = this.selected
|
|
||||||
this.validateDomainName(this.form[domainType])
|
|
||||||
if (this.isValid[domainType] === false) return
|
|
||||||
|
|
||||||
const query = {
|
const query = {
|
||||||
uri: 'domains',
|
uri: 'domains' + (domainType === 'dynDomain' ? '?dyndns' : ''),
|
||||||
data: { domain: this.form[domainType] },
|
data: { domain: domain },
|
||||||
storeKey: 'domains'
|
storeKey: 'domains'
|
||||||
}
|
}
|
||||||
if (domainType === 'dynDomain') {
|
|
||||||
query.uri += '?dyndns'
|
|
||||||
query.data.domain = query.data.domain.join('.')
|
|
||||||
}
|
|
||||||
this.$store.dispatch('POST', query).then(() => {
|
this.$store.dispatch('POST', query).then(() => {
|
||||||
this.$router.push({ name: 'domain-list' })
|
this.$router.push({ name: 'domain-list' })
|
||||||
}).catch(error => {
|
}).catch(error => {
|
||||||
this.error[domainType] = error.message
|
this.error[domainType] = error.message
|
||||||
this.isValid[domainType] = false
|
this.isValid[domainType] = false
|
||||||
})
|
})
|
||||||
},
|
|
||||||
|
|
||||||
validateDomainName (name) {
|
|
||||||
const domainType = this.selected
|
|
||||||
const domainname = domainType === 'domain' ? name : name[0]
|
|
||||||
const regex = domainType === 'domain' ? '^[.a-z0-9-]+$' : '^[a-z0-9-]+$'
|
|
||||||
let error = ''
|
|
||||||
if (!domainname.match(regex)) {
|
|
||||||
error = this.$i18n.t(`form_errors.${domainType}_syntax`)
|
|
||||||
}
|
|
||||||
this.error[this.selected] = error
|
|
||||||
this.isValid[this.selected] = error === '' ? null : false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
created () {
|
|
||||||
this.$store.dispatch('FETCH', { uri: 'domains' }).then(() => {
|
|
||||||
if (this.dynDnsForbiden) {
|
|
||||||
this.selected = 'domain'
|
|
||||||
}
|
|
||||||
})
|
|
||||||
},
|
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
AdressInputSelect,
|
DomainForm
|
||||||
BasicForm
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
|
||||||
</style>
|
|
||||||
|
|
|
@ -1,39 +1,25 @@
|
||||||
<template>
|
<template>
|
||||||
<basic-form :header="$t('tools_adminpw')" @submit.prevent="onSubmit">
|
<password-form
|
||||||
<b-alert variant="warning" show>
|
:title="$t('postinstall_set_password')" :submit-text="$t('next')"
|
||||||
{{ $t('good_practices_about_admin_password') }}
|
:error="error" :is-valid="isValid"
|
||||||
</b-alert>
|
@submit="onSubmit"
|
||||||
|
>
|
||||||
<!-- CURRENT ADMIN PASSWORD -->
|
<template v-slot:input>
|
||||||
<input-helper
|
<!-- CURRENT ADMIN PASSWORD -->
|
||||||
id="current-password" type="password" :label="$t('tools_adminpw_current')"
|
<input-helper
|
||||||
v-model="form.currentPassword" :placeholder="$t('tools_adminpw_current_placeholder')"
|
id="current-password" type="password" :label="$t('tools_adminpw_current')"
|
||||||
:state="isValid.currentPassword" :error="error.currentPassword"
|
v-model="currentPassword" :placeholder="$t('tools_adminpw_current_placeholder')"
|
||||||
@input="validateCurrentPassword"
|
:state="isValid.currentPassword" :error="error.currentPassword"
|
||||||
/>
|
@input="validateCurrentPassword"
|
||||||
|
/>
|
||||||
<hr>
|
<hr>
|
||||||
<!-- NEW ADMIN PASSWORD -->
|
</template>
|
||||||
<input-helper
|
</password-form>
|
||||||
id="password" type="password" :label="$t('password_new')"
|
|
||||||
v-model="form.password" :placeholder="$t('tools_adminpw_new_placeholder')"
|
|
||||||
:state="isValid.password" :error="error.password"
|
|
||||||
@input="validateNewPassword"
|
|
||||||
/>
|
|
||||||
|
|
||||||
<!-- NEW ADMIN PASSWORD CONFIRMATION -->
|
|
||||||
<input-helper
|
|
||||||
id="confirmation" type="password" :label="$t('password_confirmation')"
|
|
||||||
v-model="form.confirmation" :placeholder="$t('tools_adminpw_confirm_placeholder')"
|
|
||||||
:state="isValid.confirmation" :error="$t('passwords_dont_match')"
|
|
||||||
@input="validateNewPassword"
|
|
||||||
/>
|
|
||||||
</basic-form>
|
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import api from '@/helpers/api'
|
import api from '@/helpers/api'
|
||||||
import BasicForm from '@/components/BasicForm'
|
import { PasswordForm } from '@/components/reusableForms'
|
||||||
import InputHelper from '@/components/InputHelper'
|
import InputHelper from '@/components/InputHelper'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
|
@ -41,34 +27,28 @@ export default {
|
||||||
|
|
||||||
data () {
|
data () {
|
||||||
return {
|
return {
|
||||||
form: {
|
currentPassword: '',
|
||||||
currentPassword: '',
|
|
||||||
password: '',
|
|
||||||
confirmation: ''
|
|
||||||
},
|
|
||||||
isValid: {
|
isValid: {
|
||||||
currentPassword: null,
|
currentPassword: null,
|
||||||
password: null,
|
password: null,
|
||||||
confirmation: null
|
confirmation: null
|
||||||
},
|
},
|
||||||
error: {
|
error: {
|
||||||
currentPassword: this.$i18n.t('passwords_too_short'),
|
currentPassword: '',
|
||||||
password: this.$i18n.t('passwords_too_short')
|
password: '',
|
||||||
|
confirmation: ''
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
methods: {
|
methods: {
|
||||||
onSubmit () {
|
onSubmit (password) {
|
||||||
for (const key in this.isValid) {
|
if (this.isValid.currentPassword === false) return
|
||||||
if (this.isValid[key] === false) return
|
|
||||||
}
|
api.post('login', { password: this.currentPassword }).then(() => {
|
||||||
const { currentPassword, password } = this.form
|
|
||||||
api.post('login', { password: currentPassword }).then(() => {
|
|
||||||
api.put('adminpw', { new_password: password }).then(() => {
|
api.put('adminpw', { new_password: password }).then(() => {
|
||||||
this.$store.dispatch('LOGOUT').then(() => {
|
this.$store.dispatch('DISCONNECT')
|
||||||
this.$router.push({ name: 'login' })
|
this.$router.push({ name: 'login' })
|
||||||
})
|
|
||||||
}).catch(err => {
|
}).catch(err => {
|
||||||
this.error.password = err.message
|
this.error.password = err.message
|
||||||
this.isValid.password = false
|
this.isValid.password = false
|
||||||
|
@ -79,26 +59,15 @@ export default {
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
|
|
||||||
isValidPassword (password) {
|
|
||||||
return password.length >= 8 ? null : false
|
|
||||||
},
|
|
||||||
|
|
||||||
validateCurrentPassword () {
|
validateCurrentPassword () {
|
||||||
this.error.currentPassword = this.$i18n.t('passwords_too_short')
|
this.error.currentPassword = this.$i18n.t('passwords_too_short')
|
||||||
this.isValid.currentPassword = this.isValidPassword(this.form.currentPassword)
|
this.isValid.currentPassword = this.currentPassword.length >= 8 ? null : false
|
||||||
},
|
|
||||||
|
|
||||||
validateNewPassword () {
|
|
||||||
const { password, confirmation } = this.form
|
|
||||||
this.error.password = this.$i18n.t('passwords_too_short')
|
|
||||||
this.isValid.password = this.isValidPassword(password)
|
|
||||||
this.isValid.confirmation = password === confirmation ? null : false
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
components: {
|
components: {
|
||||||
InputHelper,
|
InputHelper,
|
||||||
BasicForm
|
PasswordForm
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in a new issue