Files
exchange/resources/assets/js/pages/auth/login.vue
T
Jack Goh bc49e39df7 added admin status to booking table
updated admin progress track steps
added dummy template in admin booking
2018-06-22 12:31:51 +08:00

114 lines
3.1 KiB
Vue

<template>
<div class="row">
<div class="col-lg-8 m-auto">
<card :title="$t('login')">
<form @submit.prevent="login" @keydown="form.onKeydown($event)">
<!-- Email -->
<div class="form-group row">
<label class="col-md-3 col-form-label text-md-right">{{ $t('email') }}</label>
<div class="col-md-7">
<input v-model="form.email" :class="{ 'is-invalid': form.errors.has('email') }" class="form-control" type="email" name="email">
<has-error :form="form" field="email"/>
</div>
</div>
<!-- Password -->
<div class="form-group row">
<label class="col-md-3 col-form-label text-md-right">{{ $t('password') }}</label>
<div class="col-md-7">
<input v-model="form.password" :class="{ 'is-invalid': form.errors.has('password') }" class="form-control" type="password" name="password">
<has-error :form="form" field="password"/>
</div>
</div>
<!-- Remember Me -->
<div class="form-group row">
<div class="col-md-3"/>
<div class="col-md-7 d-flex">
<checkbox v-model="remember" name="remember">
{{ $t('remember_me') }}
</checkbox>
<router-link :to="{ name: 'password.request' }" class="small ml-auto my-auto">
{{ $t('forgot_password') }}
</router-link>
</div>
</div>
<div class="form-group row">
<div class="col-md-7 offset-md-3 d-flex">
<!-- Submit Button -->
<v-button :loading="form.busy">
{{ $t('login') }}
</v-button>
<!-- <el-button type="primary" @click="openFullScreen2">As a service</el-button> -->
<!-- GitHub Login Button -->
<login-with-github/>
</div>
</div>
</form>
</card>
</div>
</div>
</template>
<script>
import Form from 'vform'
import LoginWithGithub from '~/components/LoginWithGithub'
import store from '~/store'
export default {
middleware: 'guest',
components: {
LoginWithGithub
},
metaInfo () {
return { title: this.$t('login') }
},
data: () => ({
form: new Form({
email: '',
password: ''
}),
remember: false
}),
methods: {
async login () {
// Submit the form.
const { data } = await this.form.post('/api/login')
// Add loading screen
const loading = this.$loading({
lock: true,
text: 'Logging in',
spinner: 'el-icon-loading',
background: 'rgba(0, 0, 0, 0.7)'
})
// Save the token.
this.$store.dispatch('auth/saveToken', {
token: data.token,
remember: this.remember
})
// Fetch the user.
await this.$store.dispatch('auth/fetchUser')
// Redirect home.
if (store.getters['auth/user'].role === 'admin') {
this.$router.push({ name: 'admin.home' })
loading.close()
}
this.$router.push({ name: 'home' })
loading.close()
}
}
}
</script>