|
1 | 1 | <template> |
2 | | - <v-row align="center" justify="center"> |
3 | | - <v-col cols="12" sm="8" md="4"> |
4 | | - <v-card flat class="mt-12"> |
5 | | - <v-toolbar color="secondary" dark flat> |
6 | | - <v-toolbar-title>Login form</v-toolbar-title> |
7 | | - </v-toolbar> |
8 | | - <v-form @submit.prevent="validate" ref="form"> |
9 | | - <v-card-text> |
10 | | - <v-text-field |
11 | | - v-bind="fields.username" |
12 | | - v-model="fields.username.value" |
13 | | - :disabled="isSubmitting" |
14 | | - /> |
| 2 | + <v-row align="center" justify="center"> |
| 3 | + <v-col cols="12" sm="8" md="4"> |
| 4 | + <v-card flat class="mt-12"> |
| 5 | + <v-toolbar color="secondary" dark flat> |
| 6 | + <v-toolbar-title>Login form</v-toolbar-title> |
| 7 | + </v-toolbar> |
| 8 | + <v-form @submit.prevent="validate" ref="form"> |
| 9 | + <v-card-text> |
| 10 | + <v-text-field |
| 11 | + v-bind="fields.username" |
| 12 | + v-model="fields.username.value" |
| 13 | + :disabled="isSubmitting" |
| 14 | + /> |
15 | 15 |
|
16 | | - <v-text-field |
17 | | - v-bind="fields.password" |
18 | | - v-model="fields.password.value" |
19 | | - :disabled="isSubmitting" |
20 | | - /> |
21 | | - </v-card-text> |
| 16 | + <v-text-field |
| 17 | + v-bind="fields.password" |
| 18 | + v-model="fields.password.value" |
| 19 | + :disabled="isSubmitting" |
| 20 | + /> |
| 21 | + </v-card-text> |
22 | 22 |
|
23 | | - <v-card-text> |
24 | | - <router-link :to="{ name: 'reset-password' }" |
25 | | - >Forgot your password?</router-link |
26 | | - > |
27 | | - </v-card-text> |
| 23 | + <v-card-text> |
| 24 | + <router-link :to="{ name: 'reset-password' }">Forgot your password?</router-link> |
| 25 | + </v-card-text> |
28 | 26 |
|
29 | | - <v-card-actions> |
30 | | - <v-spacer /> |
31 | | - <v-btn |
32 | | - color="secondary darken-2" |
33 | | - type="submit" |
34 | | - dark |
35 | | - :disabled="isSubmitting" |
36 | | - > |
37 | | - Sign In |
38 | | - </v-btn> |
39 | | - </v-card-actions> |
40 | | - </v-form> |
41 | | - </v-card> |
42 | | - </v-col> |
43 | | - </v-row> |
| 27 | + <v-card-actions> |
| 28 | + <v-spacer /> |
| 29 | + <v-btn color="secondary darken-2" type="submit" dark :disabled="isSubmitting">Sign In</v-btn> |
| 30 | + </v-card-actions> |
| 31 | + </v-form> |
| 32 | + </v-card> |
| 33 | + </v-col> |
| 34 | + </v-row> |
44 | 35 | </template> |
45 | 36 |
|
46 | 37 | <script> |
47 | 38 | import { auth } from "@/api"; |
48 | 39 | export default { |
49 | | - name: "login", |
50 | | - methods: { |
51 | | - async submit() { |
52 | | - if (this.isSubmitting) { |
53 | | - return; |
54 | | - } |
55 | | - this.isSubmitting = true; |
56 | | - try { |
57 | | - await auth.login( |
58 | | - this.fields.username.value, |
59 | | - this.fields.password.value |
60 | | - ); |
61 | | - localStorage.setItem("lastEmail", this.fields.username.value); |
62 | | - this.$store.dispatch("Snackbar/showInfo", "Successfully Logged In"); |
63 | | - this.$router.push({ name: "quiz" }); |
64 | | - } catch (err) { |
65 | | - this.$store.dispatch("Snackbar/showError", err); |
66 | | - } |
67 | | - this.isSubmitting = false; |
68 | | - }, |
69 | | - validate() { |
70 | | - if (this.$refs.form.validate()) { |
71 | | - this.submit(); |
72 | | - } |
73 | | - } |
74 | | - }, |
75 | | - data() { |
76 | | - return { |
77 | | - isSubmitting: false, |
78 | | - fields: { |
79 | | - username: { |
80 | | - label: "Username", |
81 | | - type: "text", |
82 | | - value: localStorage.getItem("lastEmail"), |
83 | | - rules: [v => !!v || "Please provide a username"] |
84 | | - }, |
85 | | - password: { |
86 | | - label: "Password", |
87 | | - type: "password", |
88 | | - value: "", |
89 | | - rules: [v => !!v || "Please provide a password"] |
90 | | - } |
91 | | - } |
92 | | - }; |
93 | | - } |
| 40 | + name: "login", |
| 41 | + methods: { |
| 42 | + async submit() { |
| 43 | + if (this.isSubmitting) { |
| 44 | + return; |
| 45 | + } |
| 46 | + this.isSubmitting = true; |
| 47 | + try { |
| 48 | + await auth.login( |
| 49 | + this.fields.username.value, |
| 50 | + this.fields.password.value |
| 51 | + ); |
| 52 | + localStorage.setItem("lastUsername", this.fields.username.value); |
| 53 | + this.$store.dispatch("Snackbar/showInfo", "Successfully Logged In"); |
| 54 | + this.$router.push({ name: "quiz" }); |
| 55 | + } catch (err) { |
| 56 | + this.$store.dispatch("Snackbar/showError", err); |
| 57 | + } |
| 58 | + this.isSubmitting = false; |
| 59 | + }, |
| 60 | + validate() { |
| 61 | + if (this.$refs.form.validate()) { |
| 62 | + this.submit(); |
| 63 | + } |
| 64 | + } |
| 65 | + }, |
| 66 | + data() { |
| 67 | + return { |
| 68 | + isSubmitting: false, |
| 69 | + fields: { |
| 70 | + username: { |
| 71 | + label: "Username", |
| 72 | + type: "text", |
| 73 | + value: localStorage.getItem("lastEmail"), |
| 74 | + rules: [v => !!v || "Please provide a username"] |
| 75 | + }, |
| 76 | + password: { |
| 77 | + label: "Password", |
| 78 | + type: "password", |
| 79 | + value: "", |
| 80 | + rules: [v => !!v || "Please provide a password"] |
| 81 | + } |
| 82 | + } |
| 83 | + }; |
| 84 | + } |
94 | 85 | }; |
95 | 86 | </script> |
0 commit comments