aboutsummaryrefslogtreecommitdiff
path: root/src/site/views/Auth/Register.vue
blob: 93f349ff3531a2d59f786ef22bbaa39f5cc4c744 (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
<style lang="scss" scoped>
	@import '../../styles/colors.scss';
</style>

<template>
	<section id="register"
		class="hero is-fullheight">
		<Navbar/>
		<div class="hero-body">
			<div class="container">
				<h1 class="title">
					Dashboard Access
				</h1>
				<h2 class="subtitle">
					Register for a new account
				</h2>
				<div class="columns">
					<div class="column is-4">
						<b-field>
							<b-input v-model="username"
								type="text"
								placeholder="Username"/>
						</b-field>
						<b-field>
							<b-input v-model="password"
								type="password"
								placeholder="Password"
								password-reveal/>
						</b-field>
						<b-field>
							<b-input v-model="rePassword"
								type="password"
								placeholder="Re-type Password"
								password-reveal
								@keyup.enter.native="register"/>
						</b-field>

						<p class="control has-addons is-pulled-right">
							<router-link to="/login"
								class="is-text">Already have an account?</router-link>
							<a :class="{ 'is-loading': isLoading }"
								class="button is-themed"
								@click="register">Register</a>
						</p>
					</div>
				</div>
			</div>
		</div>
	</section>
</template>

<script>
import Navbar from '../../components/navbar/Navbar.vue';

export default {
	name: 'Register',
	components: { Navbar },
	data() {
		return {
			username: null,
			password: null,
			rePassword: null,
			isLoading: false
		};
	},
	metaInfo() {
		return { title: 'Register' };
	},
	mounted() {
		this.$ga.page({
			page: '/register',
			title: 'Register',
			location: window.location.href
		});
	},
	methods: {
		register() {
			if (this.isLoading) return;
			if (this.password !== this.rePassword) {
				this.$showToast('Passwords don\'t match', true);
				return;
			}
			this.isLoading = true;
			this.axios.post(`${this.$config.baseURL}/auth/register`, {
				username: this.username,
				password: this.password
			}).then(response => {
				this.$showToast(response.data.message);
				this.isLoading = false;
				return this.$router.push('/login');
			}).catch(err => {
				this.isLoading = false;
				this.$onPromiseError(err);
			});
		}
	}
};
</script>