frontend/src/components/user/Login.vue

78 lines
2.1 KiB
Vue
Raw Normal View History

2018-09-06 17:46:38 +00:00
<template>
2018-11-01 21:34:29 +00:00
<div>
<h2 class="title">Login</h2>
<div class="box">
<form id="loginform" @submit.prevent="submit">
<div class="field">
<div class="control">
<input type="text" class="input" name="username" placeholder="Username" v-model="credentials.username" required>
2018-09-06 18:15:49 +00:00
</div>
2018-11-01 21:34:29 +00:00
</div>
<div class="field">
<div class="control">
<input type="password" class="input" name="password" placeholder="Password" v-model="credentials.password" required>
2018-09-06 18:15:49 +00:00
</div>
2018-11-01 21:34:29 +00:00
</div>
2018-09-06 18:15:49 +00:00
2018-11-01 21:34:29 +00:00
<div class="field is-grouped">
<div class="control">
<button type="submit" class="button is-primary" v-bind:class="{ 'is-loading': loading}">Login</button>
<router-link :to="{ name: 'register' }" class="button">Register</router-link>
<router-link :to="{ name: 'getPasswordReset' }" class="reset-password-link">Reset your password</router-link>
2018-09-06 18:15:49 +00:00
</div>
2018-11-01 21:34:29 +00:00
</div>
<div class="notification is-danger" v-if="error">
{{ error }}
</div>
</form>
2018-09-06 18:15:49 +00:00
</div>
2018-09-06 17:46:38 +00:00
</div>
</template>
<script>
2018-09-08 20:27:13 +00:00
import auth from '../../auth'
import router from '../../router'
2018-09-06 17:46:38 +00:00
export default {
data() {
return {
credentials: {
username: '',
password: ''
},
error: '',
loading: false
}
},
beforeMount() {
// Check if the user is already logged in, if so, redirect him to the homepage
if (auth.user.authenticated) {
router.push({name: 'home'})
}
},
methods: {
submit() {
this.loading = true
this.error = ''
let credentials = {
username: this.credentials.username,
password: this.credentials.password
}
auth.login(this, credentials, 'home')
}
}
}
</script>
<style scoped>
2018-09-08 20:27:13 +00:00
.button {
margin: 0 0.4em 0 0;
}
2018-11-01 21:34:29 +00:00
.reset-password-link{
display: inline-block;
padding-top: 5px;
}
2018-09-06 17:46:38 +00:00
</style>