login: add card-form with admin username input to login

This commit is contained in:
axolotle 2022-10-07 13:43:49 +02:00
parent f624963458
commit 7791216be6
3 changed files with 58 additions and 33 deletions

View file

@ -551,7 +551,7 @@
"none": "None", "none": "None",
"separator": ", " "separator": ", "
}, },
"wrong_password": "Wrong password", "wrong_password_or_username": "Wrong password or username",
"yes": "Yes", "yes": "Yes",
"yunohost_admin": "YunoHost Admin", "yunohost_admin": "YunoHost Admin",
"certificate_manage": "Manage SSL certificate", "certificate_manage": "Manage SSL certificate",

View file

@ -142,8 +142,8 @@ export default {
}) })
}, },
'LOGIN' ({ dispatch }, password) { 'LOGIN' ({ dispatch }, credentials) {
return api.post('login', { credentials: password }, null, { websocket: false }).then(() => { return api.post('login', { credentials }, null, { websocket: false }).then(() => {
dispatch('CONNECT') dispatch('CONNECT')
}) })
}, },

View file

@ -1,37 +1,35 @@
<template> <template>
<b-form @submit.prevent="login"> <card-form
<b-input-group> :title="$t('login')" icon="lock"
<template v-slot:prepend> :validation="$v" :server-error="serverError"
<b-input-group-text> @submit.prevent="login"
<label class="sr-only" for="input-password">{{ $t('password') }}</label> >
<icon iname="lock" class="sm" /> <!-- ADMIN USERNAME -->
</b-input-group-text> <form-field v-bind="fields.username" v-model="form.username" :validation="$v.form.username" />
</template>
<b-form-input <!-- ADMIN PASSWORD -->
id="input-password" <form-field v-bind="fields.password" v-model="form.password" :validation="$v.form.password" />
required type="password"
v-model="password"
:placeholder="$t('administration_password')" :state="isValid"
/>
<template v-slot:append> <template #buttons>
<b-button type="submit" variant="success" :disabled="disabled"> <b-button
type="submit" variant="success"
:disabled="disabled" form="ynh-form"
>
{{ $t('login') }} {{ $t('login') }}
</b-button> </b-button>
</template> </template>
</b-input-group> </card-form>
<b-form-invalid-feedback :state="isValid">
{{ $t('wrong_password') }}
</b-form-invalid-feedback>
</b-form>
</template> </template>
<script> <script>
import { validationMixin } from 'vuelidate'
import { alphalownum_, required, minLength } from '@/helpers/validators'
export default { export default {
name: 'Login', name: 'Login',
mixins: [validationMixin],
props: { props: {
skipInstallCheck: { type: Boolean, default: false }, skipInstallCheck: { type: Boolean, default: false },
forceReload: { type: Boolean, default: false } forceReload: { type: Boolean, default: false }
@ -40,15 +38,42 @@ export default {
data () { data () {
return { return {
disabled: !this.skipInstallCheck, disabled: !this.skipInstallCheck,
password: '', serverError: '',
isValid: null, form: {
apiError: undefined username: '',
password: ''
},
fields: {
username: {
label: this.$i18n.t('user_username'),
props: {
id: 'username'
}
},
password: {
label: this.$i18n.t('password'),
props: {
id: 'password',
type: 'password'
}
}
}
}
},
validations () {
return {
form: {
username: { required, alphalownum_ },
password: { required, passwordLenght: minLength(8) }
}
} }
}, },
methods: { methods: {
login () { login () {
this.$store.dispatch('LOGIN', this.password).then(() => { const credentials = [this.form.username, this.form.password].join(':')
this.$store.dispatch('LOGIN', credentials).then(() => {
if (this.forceReload) { if (this.forceReload) {
window.location.href = '/yunohost/admin/' window.location.href = '/yunohost/admin/'
} else { } else {
@ -56,7 +81,7 @@ export default {
} }
}).catch(err => { }).catch(err => {
if (err.name !== 'APIUnauthorizedError') throw err if (err.name !== 'APIUnauthorizedError') throw err
this.isValid = false this.serverError = this.$i18n.t('wrong_password_or_username')
}) })
} }
}, },