-
Notifications
You must be signed in to change notification settings - Fork 10
/
new.vue
97 lines (96 loc) · 2.69 KB
/
new.vue
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
<template>
<div class="row">
<Alerts :alerts="errors" />
<div class="col-md-6 offset-md-3">
<h2>Sign up</h2>
<form class="simple_form form-horizontal">
<div class="form-group email optional user_email">
<label class="control-label email optional">
First Name
</label>
<input
v-model="form.firstName"
class="form-control string email optional"
autofocus="autofocus"
>
</div>
<div class="form-group email optional user_email">
<label class="control-label email optional">
Last Name
</label>
<input
v-model="form.lastName"
class="form-control string email optional"
autofocus="autofocus"
>
</div>
<div class="form-group email optional user_email">
<label class="control-label email optional">
Email
</label>
<input
v-model="form.email"
class="form-control string email optional"
autofocus="autofocus"
>
</div>
<div class="form-group password optional user_password">
<label class="control-label password optional">
Password
</label>
<input
v-model="form.password"
type="password"
class="form-control password optional"
>
</div>
<div class="text-center">
<button
class="btn btn-default btn btn-primary"
@click.prevent="handleSignUp"
>
Sign up
</button>
</div>
</form>
</div>
</div>
</template>
<script>
import Alerts from '~components/shared/alerts';
import _get from 'lodash/get';
import signUp from '~mutations/registerUser';
import { AUTH_TOKEN_KEY } from '~configuration/appConstants';
import { mapMutations } from 'vuex';
export default {
name: 'SignUp',
components: { Alerts },
data() {
return {
errors: [],
form: {},
};
},
methods: {
...mapMutations(['signIn']),
handleSignUp() {
signUp({
apollo: this.$apollo,
...this.form,
}).then(response => _get(response, 'data.registerUser', {}))
.then(response => {
if(response.success) {
const user = response.user;
this.signIn(user); // using the Vuex store
localStorage.setItem(AUTH_TOKEN_KEY, user.authenticationToken);
this.$router.push({ name: 'home' });
} else {
this.errors = this.errorMessages(response.data.registerUser.errors);
}
}).catch(error => {
this.errors = [error];
});
},
},
};
</script>