blob: 20a22b67d5edf9872bc134f5d6a0ba5a63a8a5d5 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
<template>
<section class="section is-fullheight is-register">
<div class="container">
<h1 class="title">
Dashboard Access
</h1>
<h2 class="subtitle mb5">
Register for a new account
</h2>
<div class="columns">
<div class="column is-4 is-offset-4">
<b-field>
<b-input
v-model="username"
class="hostess-input"
type="text"
placeholder="Username" />
</b-field>
<b-field>
<b-input
v-model="password"
class="hostess-input"
type="password"
placeholder="Password"
password-reveal />
</b-field>
<b-field>
<b-input
v-model="rePassword"
class="hostess-input"
type="password"
placeholder="Re-type Password"
password-reveal
@keyup.enter.native="register" />
</b-field>
<div class="level">
<!-- Left side -->
<div class="level-left">
<div class="level-item">
<router-link
to="/login"
class="is-text">
Already have an account?
</router-link>
</div>
</div>
<!-- Right side -->
<div class="level-right">
<p class="level-item">
<b-button
size="is-medium"
type="is-hostess"
:disabled="isLoading"
@click="register">
Register
</b-button>
</p>
</div>
</div>
</div>
</div>
</div>
</section>
</template>
<script>
import { mapState } from 'vuex';
export default {
name: 'Register',
data() {
return {
username: null,
password: null,
rePassword: null,
isLoading: false
};
},
computed: mapState(['config', 'auth']),
methods: {
async register() {
if (this.isLoading) return;
if (!this.username || !this.password || !this.rePassword) {
this.$notifier.error('Please fill all fields before attempting to register.');
return;
}
if (this.password !== this.rePassword) {
this.$notifier.error('Passwords don\'t match');
return;
}
this.isLoading = true;
try {
const response = await this.$store.dispatch('auth/register', {
username: this.username,
password: this.password
});
this.$notifier.success(response.message);
this.$router.push('/login');
return;
} catch (error) {
this.$notifier.error(error.message);
} finally {
this.isLoading = false;
}
}
},
head() {
return {
title: 'Register'
};
}
};
</script>
|