frontend/src/components/user/Register.vue

96 lines
2.3 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">Register</h2>
<div class="box">
<form id="registerform" @submit.prevent="submit">
<div class="field">
<div class="control">
2018-12-25 15:03:51 +00:00
<input v-focus 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="text" class="input" name="email" placeholder="E-mail address" v-model="credentials.email" required>
2018-09-08 20:27:13 +00:00
</div>
2018-11-01 21:34:29 +00:00
</div>
<div class="field">
<div class="control">
<input type="password" class="input" name="password1" placeholder="Password" v-model="credentials.password" required>
2018-09-08 20:27:13 +00:00
</div>
2018-11-01 21:34:29 +00:00
</div>
<div class="field">
<div class="control">
<input type="password" class="input" name="password2" placeholder="Retype password" v-model="credentials.password2" 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}">Register</button>
<router-link :to="{ name: 'login' }" class="button">Login</router-link>
2018-09-06 18:15:49 +00:00
</div>
2018-11-01 21:34:29 +00:00
</div>
<div class="notification is-info" v-if="loading">
Loading...
</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>
import auth from '../../auth'
import router from '../../router'
2018-09-06 17:46:38 +00:00
export default {
data() {
return {
credentials: {
username: '',
2018-09-08 20:27:13 +00:00
email: '',
password: '',
password2: '',
},
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
2018-09-08 20:27:13 +00:00
this.error = ''
2018-09-08 20:27:13 +00:00
if (this.credentials.password2 !== this.credentials.password) {
this.loading = false
this.error = 'Passwords don\'t match'
2018-09-08 20:27:13 +00:00
return
}
let credentials = {
username: this.credentials.username,
email: this.credentials.email,
password: this.credentials.password
}
2018-09-06 17:46:38 +00:00
auth.register(this, credentials, 'home')
}
}
}
2018-09-06 17:46:38 +00:00
</script>
<style scoped>
2018-09-08 20:27:13 +00:00
.button {
margin: 0 0.4em 0 0;
}
2018-09-06 17:46:38 +00:00
</style>