2018-09-06 19:46:38 +02:00
|
|
|
<template>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div>
|
2019-10-19 16:27:56 +02:00
|
|
|
<h2 class="title has-text-centered">Register</h2>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="box">
|
|
|
|
<form id="registerform" @submit.prevent="submit">
|
|
|
|
<div class="field">
|
2019-10-19 16:27:56 +02:00
|
|
|
<label class="label" for="username">Username</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2019-10-19 16:27:56 +02:00
|
|
|
<input v-focus type="text" id="username" class="input" name="username" placeholder="e.g. frederick" v-model="credentials.username" required/>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2019-10-19 16:27:56 +02:00
|
|
|
<label class="label" for="email">E-mail address</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2020-02-17 17:28:46 +00:00
|
|
|
<input type="email" class="input" id="email" name="email" placeholder="e.g. frederic@vikunja.io" v-model="credentials.email" required/>
|
2018-09-08 22:27:13 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2019-10-19 16:27:56 +02:00
|
|
|
<label class="label" for="password1">Password</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2019-10-19 16:27:56 +02:00
|
|
|
<input type="password" class="input" id="password1" name="password1" placeholder="e.g. ••••••••••••" v-model="credentials.password" required/>
|
2018-09-08 22:27:13 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="field">
|
2019-10-19 16:27:56 +02:00
|
|
|
<label class="label" for="password2">Retype your password</label>
|
2018-11-01 21:34:29 +00:00
|
|
|
<div class="control">
|
2019-10-19 16:27:56 +02:00
|
|
|
<input type="password" class="input" id="password2" name="password2" placeholder="e.g. ••••••••••••" v-model="credentials.password2" required/>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
2018-09-06 20:15:49 +02: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>
|
2020-06-17 22:24:37 +02:00
|
|
|
<router-link :to="{ name: 'user.login' }" class="button">Login</router-link>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
<div class="notification is-info" v-if="loading">
|
|
|
|
Loading...
|
|
|
|
</div>
|
2020-05-08 18:43:51 +00:00
|
|
|
<div class="notification is-danger" v-if="errorMessage !== ''">
|
|
|
|
{{ errorMessage }}
|
2018-11-01 21:34:29 +00:00
|
|
|
</div>
|
|
|
|
</form>
|
2018-09-06 20:15:49 +02:00
|
|
|
</div>
|
2018-09-06 19:46:38 +02:00
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2019-03-02 10:25:10 +00:00
|
|
|
import router from '../../router'
|
2020-05-08 18:43:51 +00:00
|
|
|
import {mapState} from 'vuex'
|
|
|
|
import {ERROR_MESSAGE, LOADING} from '../../store/mutation-types'
|
2018-09-06 19:46:38 +02:00
|
|
|
|
2019-03-02 10:25:10 +00:00
|
|
|
export default {
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
credentials: {
|
|
|
|
username: '',
|
2018-09-08 22:27:13 +02:00
|
|
|
email: '',
|
2019-03-02 10:25:10 +00:00
|
|
|
password: '',
|
|
|
|
password2: '',
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
beforeMount() {
|
|
|
|
// Check if the user is already logged in, if so, redirect him to the homepage
|
2020-05-08 18:43:51 +00:00
|
|
|
if (this.authenticated) {
|
2019-03-02 10:25:10 +00:00
|
|
|
router.push({name: 'home'})
|
|
|
|
}
|
|
|
|
},
|
2020-07-07 20:07:13 +00:00
|
|
|
mounted() {
|
|
|
|
this.setTitle('Register')
|
|
|
|
},
|
2020-05-08 18:43:51 +00:00
|
|
|
computed: mapState({
|
|
|
|
authenticated: state => state.auth.authenticated,
|
|
|
|
loading: LOADING,
|
|
|
|
errorMessage: ERROR_MESSAGE,
|
|
|
|
}),
|
2019-03-02 10:25:10 +00:00
|
|
|
methods: {
|
|
|
|
submit() {
|
2020-05-08 18:43:51 +00:00
|
|
|
this.$store.commit(LOADING, true)
|
|
|
|
this.$store.commit(ERROR_MESSAGE, '')
|
2018-09-08 22:27:13 +02:00
|
|
|
|
|
|
|
if (this.credentials.password2 !== this.credentials.password) {
|
2020-05-08 18:43:51 +00:00
|
|
|
this.$store.commit(ERROR_MESSAGE, 'Passwords don\'t match.')
|
|
|
|
this.$store.commit(LOADING, false)
|
2018-09-08 22:27:13 +02:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-05-08 18:43:51 +00:00
|
|
|
const credentials = {
|
2019-03-02 10:25:10 +00:00
|
|
|
username: this.credentials.username,
|
|
|
|
email: this.credentials.email,
|
|
|
|
password: this.credentials.password
|
|
|
|
}
|
2018-09-06 19:46:38 +02:00
|
|
|
|
2020-05-08 18:43:51 +00:00
|
|
|
this.$store.dispatch('auth/register', credentials)
|
2019-03-02 10:25:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-06 19:46:38 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
2018-09-08 22:27:13 +02:00
|
|
|
.button {
|
|
|
|
margin: 0 0.4em 0 0;
|
|
|
|
}
|
2018-09-06 19:46:38 +02:00
|
|
|
</style>
|