Files
gancio/pages/login.vue

80 lines
2.3 KiB
Vue
Raw Normal View History

2019-04-03 00:25:12 +02:00
<template lang='pug'>
2019-05-30 12:04:14 +02:00
2019-06-06 23:54:32 +02:00
el-card
2019-05-30 12:04:14 +02:00
2019-06-06 23:54:32 +02:00
nuxt-link.float-right(to='/')
v-icon(name='times' color='red')
h5 {{$t('common.login')}}
el-form(v-loading='loading' method='POST' action='/api/auth/login')
2019-04-26 23:14:43 +02:00
p(v-html="$t('login.description')")
2019-05-30 12:04:14 +02:00
2019-06-06 23:54:32 +02:00
el-input.mb-2(v-model='email' type='email' name='email'
:placeholder='$t("common.email")' autocomplete='email' ref='email')
v-icon(name='user' slot='prepend')
2019-05-30 12:04:14 +02:00
2019-06-06 23:54:32 +02:00
el-input.mb-1(v-model='password' @keyup.enter.native="submit" name='password'
type='password' :placeholder='$t("common.password")')
v-icon(name='lock' slot='prepend')
2019-05-30 12:04:14 +02:00
2019-06-06 23:54:32 +02:00
el-button.mr-1(plain type="success" native-type='submit'
:disabled='disabled' @click='submit') {{$t('common.login')}}
2019-05-30 12:04:14 +02:00
nuxt-link(to='/register' v-if='settings.allow_registration')
2019-04-26 23:14:43 +02:00
el-button.mt-1(plain type="primary") {{$t('login.not_registered')}}
2019-05-30 12:04:14 +02:00
2019-04-26 23:14:43 +02:00
a.float-right(href='#' @click='forgot') {{$t('login.forgot_password')}}
2019-04-03 00:25:12 +02:00
</template>
<script>
import { mapActions, mapState } from 'vuex'
2019-04-03 00:25:12 +02:00
import { Message } from 'element-ui'
2019-05-30 12:04:14 +02:00
import get from 'lodash/get'
2019-04-03 00:25:12 +02:00
export default {
name: 'Login',
data () {
return {
password: '',
email: '',
loading: false
}
},
2019-06-06 23:54:32 +02:00
computed: {
...mapState(['settings']),
2019-06-06 23:54:32 +02:00
disabled () {
if (process.server) return false
return !this.email || !this.password
}
},
2019-04-03 00:25:12 +02:00
methods: {
...mapActions(['login']),
async forgot () {
if (!this.email) {
2019-04-26 23:14:43 +02:00
Message({ message: this.$t('login.insert_email'), type: 'error' })
2019-04-03 00:25:12 +02:00
this.$refs.email.focus()
return
}
this.loading = true
2019-05-30 12:04:14 +02:00
await this.$axios.$post('/user/recover', { email: this.email })
2019-04-03 00:25:12 +02:00
this.loading = false
2019-04-26 23:14:43 +02:00
Message({ message: this.$t('login.check_email'), type: 'success' })
2019-04-03 00:25:12 +02:00
},
async submit (e) {
e.preventDefault()
try {
this.loading = true
2019-04-26 23:14:43 +02:00
await this.$auth.loginWith('local', { data: { email: this.email, password: this.password } })
2019-04-03 00:25:12 +02:00
this.loading = false
2019-04-26 23:14:43 +02:00
Message({ message: this.$t('login.ok'), type: 'success' })
2019-04-03 00:25:12 +02:00
} catch (e) {
2019-05-30 12:04:14 +02:00
e = get(e, 'response.data.message', e)
Message({ message: this.$t('login.error') + this.$t(e), type: 'error' })
2019-04-03 00:25:12 +02:00
this.loading = false
return
}
this.email = this.password = ''
}
}
}
</script>