|
1 | 1 | <template> |
2 | | - <div> |
3 | | - <form @submit.prevent="signup"> |
4 | | - <h1>Sign Up</h1> |
5 | | - <label for="firstname">Firstname</label> |
6 | | - <div> |
7 | | - <input id="firstname" type="text" v-model="firstname" required autofocus /> |
8 | | - </div> |
9 | | - |
10 | | - <label for="firstname">Lastname</label> |
11 | | - <div> |
12 | | - <input id="lastname" type="text" v-model="lastname" required autofocus /> |
13 | | - </div> |
14 | | - |
15 | | - <label for="email">E-Mail Address</label> |
16 | | - <div> |
17 | | - <input id="email" type="email" v-model="email" required /> |
18 | | - </div> |
19 | | - |
20 | | - <label for="password">Password</label> |
21 | | - <div> |
22 | | - <input id="password" type="password" v-model="password" required /> |
23 | | - </div> |
24 | | - |
25 | | - <label for="password-confirm">Confirm Password</label> |
26 | | - <div> |
27 | | - <input id="password-confirm" type="password" v-model="password_confirmation" required /> |
28 | | - </div> |
29 | | - |
30 | | - <div> |
31 | | - <button type="submit">Sign Up</button> |
32 | | - </div> |
33 | | - </form> |
34 | | - </div> |
| 2 | + <v-container fluid> |
| 3 | + <v-row> |
| 4 | + <v-col cols="12"> |
| 5 | + <v-row align="start" justify="center"> |
| 6 | + <v-card class="ma-4 pa-8" outlined tile width="100%"> |
| 7 | + <v-form ref="form" v-model="valid"> |
| 8 | + <v-container> |
| 9 | + <v-row> |
| 10 | + <v-col md="6" sm="12"> |
| 11 | + <v-text-field v-model="firstName" label="Firstname" required></v-text-field> |
| 12 | + </v-col> |
| 13 | + <v-col md="6" sm="12"> |
| 14 | + <v-text-field v-model="lastName" label="Lastname" required></v-text-field> |
| 15 | + </v-col> |
| 16 | + <v-col md="12" sm="12"> |
| 17 | + <v-text-field v-model="email" :rules="emailRules" label="E-mail" required></v-text-field> |
| 18 | + </v-col> |
| 19 | + <v-col md="12" sm="12"> |
| 20 | + <v-text-field :type="'password'" v-model="password" label="Password" required></v-text-field> |
| 21 | + </v-col> |
| 22 | + </v-row> |
| 23 | + <v-row> |
| 24 | + <v-btn :disabled="!valid" color="success" class="mr-4" @click="validate">Validate</v-btn> |
| 25 | + <v-btn color="error" class="mr-4" @click="reset">Reset Form</v-btn> |
| 26 | + </v-row> |
| 27 | + </v-container> |
| 28 | + </v-form> |
| 29 | + <router-link to="/signin">SignIn</router-link> if you already have an account :) ! |
| 30 | + </v-card> |
| 31 | + </v-row> |
| 32 | + </v-col> |
| 33 | + </v-row> |
| 34 | + </v-container> |
35 | 35 | </template> |
36 | 36 |
|
| 37 | + |
37 | 38 | <script> |
38 | 39 | /** |
39 | 40 | * Export default |
40 | 41 | */ |
41 | 42 | export default { |
42 | 43 | data() { |
43 | 44 | return { |
44 | | - firstname: '', |
45 | | - lastname: '', |
| 45 | + valid: false, |
| 46 | + firstName: '', |
| 47 | + lastName: '', |
46 | 48 | email: '', |
| 49 | + emailRules: [ |
| 50 | + v => !!v || 'E-mail is required', |
| 51 | + v => /.+@.+/.test(v) || 'E-mail must be valid', |
| 52 | + ], |
47 | 53 | password: '', |
48 | | - password_confirmation: '', |
49 | | - is_admin: null, |
50 | 54 | }; |
51 | 55 | }, |
52 | 56 | methods: { |
53 | | - signup() { |
54 | | - const data = { |
55 | | - firstname: this.firstname, |
56 | | - lastname: this.lastname, |
57 | | - email: this.email, |
58 | | - password: this.password, |
59 | | - is_admin: this.is_admin, |
60 | | - }; |
61 | | - this.$store |
62 | | - .dispatch('signup', data) |
63 | | - .then(() => this.$router.push('/')) |
64 | | - .catch(err => console.log(err)); |
| 57 | + validate() { |
| 58 | + if (this.$refs.form.validate()) { |
| 59 | + const { firstName } = this; |
| 60 | + const { lastName } = this; |
| 61 | + const { email } = this; |
| 62 | + const { password } = this; |
| 63 | + this.$store |
| 64 | + .dispatch('signup', { email, password, firstName, lastName }) |
| 65 | + .then(() => this.$router.push('/')) |
| 66 | + .catch(err => console.log(err)); |
| 67 | + } |
| 68 | + }, |
| 69 | + reset() { |
| 70 | + this.$refs.form.reset(); |
65 | 71 | }, |
66 | 72 | }, |
67 | 73 | }; |
|
0 commit comments