2019-04-03 00:25:12 +02:00
|
|
|
<template lang='pug'>
|
2019-05-30 12:04:14 +02:00
|
|
|
|
|
|
|
|
el-dialog(:title='$t("common.login")' :before-close='close' visible)
|
|
|
|
|
|
2019-04-03 00:25:12 +02:00
|
|
|
el-form(v-loading='loading')
|
2019-04-26 23:14:43 +02:00
|
|
|
p(v-html="$t('login.description')")
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-04-26 23:14:43 +02:00
|
|
|
el-input.mb-2(v-model='email' type='email' :placeholder='$t("common.email")' autocomplete='email' ref='email')
|
2019-05-30 12:04:14 +02:00
|
|
|
i.el-icon-user(slot='prepend')
|
|
|
|
|
|
2019-04-26 23:14:43 +02:00
|
|
|
el-input.mb-1(v-model='password' @keyup.enter.native="submit" type='password' :placeholder='$t("common.password")')
|
2019-05-30 12:04:14 +02:00
|
|
|
i.el-icon-lock(slot='prepend')
|
|
|
|
|
|
|
|
|
|
el-button.mr-1(plain type="success" :disabled='!email || !password' @click='submit') {{$t('common.login')}}
|
|
|
|
|
|
|
|
|
|
nuxt-link(to='/register')
|
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>
|
2019-04-26 23:14:43 +02:00
|
|
|
const Cookie = process.client ? require('js-cookie') : undefined
|
2019-04-03 00:25:12 +02:00
|
|
|
import { mapActions } from 'vuex'
|
|
|
|
|
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 {
|
2019-05-30 12:04:14 +02:00
|
|
|
open: true,
|
2019-04-03 00:25:12 +02:00
|
|
|
password: '',
|
|
|
|
|
email: '',
|
|
|
|
|
loading: false
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
methods: {
|
2019-05-30 12:04:14 +02:00
|
|
|
close () {
|
|
|
|
|
this.$router.replace('/')
|
|
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
...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>
|