Files
gancio/pages/Login.vue

97 lines
2.6 KiB
Vue
Raw Normal View History

2020-01-03 22:24:27 +01:00
<template lang='pug'>
2020-07-25 21:41:22 +02:00
v-row.mt-5(align='center' justify='center')
v-col(cols='12' md="6" lg="5" xl="4")
v-card
v-card-title {{$t('common.login')}}
v-card-subtitle(v-text="$t('login.description')")
v-card-text
2020-07-29 02:18:46 +02:00
v-form(v-model='valid' ref='form')
2020-07-28 12:24:39 +02:00
v-text-field(v-model='email' type='email'
2020-09-05 01:21:47 +02:00
:rules='$validators.email' autofocus
2020-07-28 12:24:39 +02:00
:placeholder='$t("common.email")'
ref='email')
2020-07-25 21:41:22 +02:00
2020-07-28 12:24:39 +02:00
v-text-field(v-model='password'
2020-09-05 01:21:47 +02:00
:rules='$validators.password'
2020-07-28 12:24:39 +02:00
type='password'
:placeholder='$t("common.password")')
2020-07-25 21:41:22 +02:00
2020-07-29 02:18:46 +02:00
v-card-actions
2020-07-31 01:03:19 +02:00
v-btn(text
tabindex="1"
@click='forgot' small) {{$t('login.forgot_password')}}
2020-07-29 02:18:46 +02:00
2020-07-25 21:41:22 +02:00
v-card-actions
2020-07-31 01:03:19 +02:00
v-spacer
2020-07-25 21:41:22 +02:00
v-btn(v-if='settings.allow_registration'
to='/register'
text
2020-07-31 01:03:19 +02:00
tabindex="1"
2020-07-25 21:41:22 +02:00
color='orange') {{$t('login.not_registered')}}
2020-07-31 01:03:19 +02:00
v-btn(color='success'
tabindex="0"
:disabled='!valid || loading' :loading='loading'
@click='submit') {{$t('common.login')}}
2020-01-03 22:24:27 +01:00
</template>
<script>
2020-01-27 00:47:03 +01:00
import { mapState } from 'vuex'
2020-01-03 22:24:27 +01:00
export default {
name: 'Login',
data () {
return {
password: '',
email: '',
2020-07-29 02:18:46 +02:00
loading: false,
valid: false
2020-01-03 22:24:27 +01:00
}
},
computed: {
2020-07-29 02:18:46 +02:00
...mapState(['settings'])
2020-01-03 22:24:27 +01:00
},
methods: {
async forgot () {
if (!this.email) {
2020-07-29 02:18:46 +02:00
// this.$root.$message({ message: this.$t('login.insert_email'), color: 'error' })
2020-01-03 22:24:27 +01:00
this.$refs.email.focus()
return
}
this.loading = true
await this.$axios.$post('/user/recover', { email: this.email })
this.loading = false
2020-07-28 12:24:39 +02:00
this.$root.$message({ message: this.$t('login.check_email'), color: 'success' })
2020-01-03 22:24:27 +01:00
},
async submit (e) {
e.preventDefault()
try {
this.loading = true
2020-01-27 00:47:03 +01:00
const data = new URLSearchParams()
data.append('username', this.email)
data.append('password', this.password)
data.append('grant_type', 'password')
data.append('client_id', 'self')
await this.$auth.loginWith('local', { data })
2020-01-03 22:24:27 +01:00
this.loading = false
2020-07-28 12:24:39 +02:00
this.$root.$message({ message: this.$t('login.ok'), color: 'success' })
2020-01-03 22:24:27 +01:00
} catch (e) {
2020-07-28 12:24:39 +02:00
this.$root.$message({ message: this.$t('login.error'), color: 'error' })
2020-01-03 22:24:27 +01:00
this.loading = false
return
}
this.email = this.password = ''
}
2020-01-13 11:18:10 +01:00
},
head () {
return {
title: this.settings.title + ' - ' + this.$t('common.login')
}
2020-01-03 22:24:27 +01:00
}
}
</script>