2019-04-03 00:25:12 +02:00
|
|
|
<template lang='pug'>
|
2019-11-03 00:52:25 +01:00
|
|
|
el-dialog(:visible='show' @close='close' :close-on-click-modal='false' @opened='() => $refs.email.focus()'
|
2019-10-22 23:47:41 +02:00
|
|
|
append-to-body :title="$t('common.login')")
|
2019-07-29 01:27:47 +02:00
|
|
|
|
2019-10-22 23:47:41 +02:00
|
|
|
p(v-html="$t('login.description')")
|
|
|
|
|
div(v-loading='loading')
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-10-22 23:47:41 +02:00
|
|
|
el-input.mb-2(v-model='email' type='email' name='email' prefix-icon='el-icon-user'
|
2019-06-06 23:54:32 +02:00
|
|
|
:placeholder='$t("common.email")' autocomplete='email' ref='email')
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-10-22 23:47:41 +02:00
|
|
|
el-input.mb-1(v-model='password' @keyup.enter.native="submit"
|
|
|
|
|
prefix-icon='el-icon-lock' name='password'
|
2019-06-06 23:54:32 +02:00
|
|
|
type='password' :placeholder='$t("common.password")')
|
2019-05-30 12:04:14 +02:00
|
|
|
|
2019-10-22 23:47:41 +02:00
|
|
|
a(href='#' @click='forgot') {{$t('login.forgot_password')}}
|
|
|
|
|
|
|
|
|
|
span(slot='footer')
|
2019-06-25 01:05:38 +02:00
|
|
|
el-button.mr-1(plain type="success"
|
2019-06-06 23:54:32 +02:00
|
|
|
:disabled='disabled' @click='submit') {{$t('common.login')}}
|
2019-10-22 23:47:41 +02:00
|
|
|
nuxt-link(to='/?ref=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-03 00:25:12 +02:00
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script>
|
2019-06-21 23:52:18 +02:00
|
|
|
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',
|
2019-10-22 23:47:41 +02:00
|
|
|
props: ['show'],
|
2019-04-03 00:25:12 +02:00
|
|
|
data () {
|
|
|
|
|
return {
|
|
|
|
|
password: '',
|
|
|
|
|
email: '',
|
2019-10-28 17:33:20 +01:00
|
|
|
loading: false
|
2019-04-03 00:25:12 +02:00
|
|
|
}
|
|
|
|
|
},
|
2019-06-06 23:54:32 +02:00
|
|
|
computed: {
|
2019-06-21 23:52:18 +02:00
|
|
|
...mapState(['settings']),
|
2019-06-06 23:54:32 +02:00
|
|
|
disabled () {
|
|
|
|
|
return !this.email || !this.password
|
|
|
|
|
}
|
|
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
methods: {
|
|
|
|
|
...mapActions(['login']),
|
2019-10-22 23:47:41 +02:00
|
|
|
close () {
|
|
|
|
|
this.$router.replace('/')
|
|
|
|
|
this.$emit('close')
|
|
|
|
|
},
|
2019-04-03 00:25:12 +02:00
|
|
|
async forgot () {
|
|
|
|
|
if (!this.email) {
|
2019-09-11 19:12:24 +02:00
|
|
|
Message({ message: this.$t('login.insert_email'), showClose: true, 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) {
|
2019-10-28 17:33:20 +01:00
|
|
|
if (this.disabled) { return false }
|
2019-04-03 00:25:12 +02:00
|
|
|
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-11-13 10:56:01 +01:00
|
|
|
const user = await this.$axios.$get('/auth/user')
|
|
|
|
|
this.$auth.setUser(user)
|
2019-04-03 00:25:12 +02:00
|
|
|
this.loading = false
|
2019-06-25 01:05:38 +02:00
|
|
|
Message({ message: this.$t('login.ok'), showClose: true, type: 'success' })
|
2019-10-22 23:47:41 +02:00
|
|
|
this.close()
|
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)
|
2019-06-25 01:05:38 +02:00
|
|
|
Message({ message: this.$t('login.error') + this.$t(e), showClose: true, type: 'error' })
|
2019-04-03 00:25:12 +02:00
|
|
|
this.loading = false
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
this.email = this.password = ''
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-10-28 17:33:20 +01:00
|
|
|
</script>
|