|
1 | 1 | <template>
|
2 |
| - <main |
3 |
| - class="container container--size-small container--top-20height container--bottom-20height" |
4 |
| - > |
| 2 | + <main class="container" style="max-width: 500px; margin: 10vh auto;"> |
5 | 3 | <LargeMessage
|
6 |
| - v-if="completedRegistration" |
| 4 | + v-if="completed" |
7 | 5 | heading="Check your email"
|
8 | 6 | img="undraw_message_sent_1030.svg"
|
9 | 7 | text="We've sent you a special link to complete your registration and activate your account."
|
10 | 8 | />
|
11 |
| - <Card v-else> |
12 |
| - <h1>Register</h1> |
13 |
| - <Loading v-if="isLoading" message="Creating your account" /> |
14 |
| - <form v-else v-meta-ctrl-enter="register" @submit.prevent="register"> |
15 |
| - <Input |
16 |
| - v-model="name" |
17 |
| - type="text" |
18 |
| - label="Name" |
19 |
| - placeholder="Enter your full name" |
20 |
| - autocomplete="name" |
21 |
| - required |
22 |
| - autofocus |
23 |
| - /> |
24 |
| - <Input |
25 |
| - v-model="email" |
26 |
| - type="email" |
27 |
| - label="Email" |
28 |
| - placeholder="Enter your work email" |
29 |
| - autocomplete="email" |
30 |
| - required |
31 |
| - /> |
32 |
| - <Input |
33 |
| - v-model="password" |
34 |
| - type="password" |
35 |
| - label="Password" |
36 |
| - placeholder="Enter a secure password" |
37 |
| - autocomplete="new-password" |
38 |
| - /> |
39 |
| - <Input |
40 |
| - v-if="showInviteCode" |
41 |
| - v-model="invitedByUser" |
42 |
| - type="text" |
43 |
| - label="Invitation code" |
44 |
| - placeholder="Enter an optional invite code" |
45 |
| - help="If you have an invite code, enter that here" |
46 |
| - /> |
47 |
| - <button |
48 |
| - class="button button--width-full button--size-large" |
49 |
| - type="submit" |
| 9 | + <div v-else class="card"> |
| 10 | + <form |
| 11 | + v-meta-ctrl-enter="login" |
| 12 | + class="card-content" |
| 13 | + @submit.prevent="login" |
| 14 | + > |
| 15 | + <b-field label="Name"> |
| 16 | + <b-input v-model="name" type="text" required /> |
| 17 | + </b-field> |
| 18 | + <b-field label="Email"> |
| 19 | + <b-input v-model="email" type="email" required /> |
| 20 | + </b-field> |
| 21 | + <b-field label="Password"> |
| 22 | + <b-input |
| 23 | + v-model="password" |
| 24 | + type="password" |
| 25 | + required |
| 26 | + password-reveal |
| 27 | + /> |
| 28 | + </b-field> |
| 29 | + <div class="field"> |
| 30 | + <b-checkbox v-model="hasInviteCode" |
| 31 | + >I have an invitation code</b-checkbox |
| 32 | + > |
| 33 | + </div> |
| 34 | + <b-field v-if="hasInviteCode" label="Invitation code"> |
| 35 | + <b-input v-model="invitedByUser" type="text" /> |
| 36 | + </b-field> |
| 37 | + <b-button type="is-primary" :loading="isLoading" native-type="submit" |
| 38 | + >Login to your account</b-button |
50 | 39 | >
|
51 |
| - Register for an account |
52 |
| - </button> |
53 |
| - <button |
54 |
| - type="button" |
55 |
| - class="button button--size-small button--width-full button--color-none" |
56 |
| - @click="showInviteCode = !showInviteCode" |
57 |
| - > |
58 |
| - I have an invite code |
59 |
| - </button> |
60 | 40 | </form>
|
61 |
| - </Card> |
62 |
| - <p v-if="!completedRegistration" class="text text--mt-1"> |
63 |
| - Already have an account? |
64 |
| - <nuxt-link to="/auth/login">Login to your account</nuxt-link> |
65 |
| - </p> |
| 41 | + </div> |
66 | 42 | </main>
|
67 | 43 | </template>
|
68 | 44 |
|
69 | 45 | <script lang="ts">
|
70 | 46 | import { Component, Vue } from "vue-property-decorator";
|
71 | 47 | import { mapGetters } from "vuex";
|
72 |
| -import Card from "@/components/Card.vue"; |
73 | 48 | import LargeMessage from "@/components/LargeMessage.vue";
|
74 |
| -import Loading from "@/components/Loading.vue"; |
75 |
| -import Input from "@/components/form/Input.vue"; |
76 |
| -
|
| 49 | +import { User } from "../../types/auth"; |
77 | 50 | @Component({
|
78 |
| - components: { |
79 |
| - Card, |
80 |
| - LargeMessage, |
81 |
| - Loading, |
82 |
| - Input, |
83 |
| - }, |
84 | 51 | computed: mapGetters({
|
85 | 52 | isAuthenticated: "auth/isAuthenticated",
|
| 53 | + user: "auth/user", |
86 | 54 | }),
|
| 55 | + components: { |
| 56 | + LargeMessage, |
| 57 | + }, |
87 | 58 | })
|
88 | 59 | export default class Login extends Vue {
|
89 | 60 | name = "";
|
90 | 61 | email = "";
|
91 | 62 | password = "";
|
92 | 63 | invitedByUser = "";
|
| 64 | + hasInviteCode = false; |
| 65 | +
|
93 | 66 | isAuthenticated!: boolean;
|
94 |
| - showInviteCode = false; |
| 67 | + user!: User; |
95 | 68 | isLoading = false;
|
96 |
| - completedRegistration = false; |
97 |
| - private register() { |
| 69 | + completed = false; |
| 70 | +
|
| 71 | + async login() { |
98 | 72 | this.isLoading = true;
|
99 |
| - this.$store |
100 |
| - .dispatch("auth/register", { |
101 |
| - email: this.email, |
| 73 | + try { |
| 74 | + const response = await this.$store.dispatch("auth/register", { |
102 | 75 | name: this.name,
|
| 76 | + email: this.email, |
103 | 77 | password: this.password,
|
104 | 78 | invitedByUser: this.invitedByUser ? this.invitedByUser : undefined,
|
105 |
| - }) |
106 |
| - .then(() => { |
107 |
| - this.completedRegistration = true; |
108 |
| - }) |
109 |
| - .catch((error) => { |
110 |
| - throw new Error(error); |
111 |
| - }) |
112 |
| - .finally(() => { |
113 |
| - this.name = ""; |
114 |
| - this.email = ""; |
115 |
| - this.password = ""; |
116 |
| - this.invitedByUser = ""; |
117 |
| - this.isLoading = false; |
118 | 79 | });
|
| 80 | + if (response === "2fa") return this.$router.push("/auth/2fa"); |
| 81 | + this.completed = true; |
| 82 | + } catch (error) {} |
| 83 | + this.isLoading = false; |
| 84 | + this.name = ""; |
| 85 | + this.email = ""; |
| 86 | + this.password = ""; |
119 | 87 | }
|
120 | 88 |
|
121 |
| - private created() { |
122 |
| - if (this.isAuthenticated) return this.$router.replace("/"); |
| 89 | + created() { |
| 90 | + if (this.isAuthenticated) |
| 91 | + return this.$router.replace( |
| 92 | + (this.$route.query.redirect as string) || "/" |
| 93 | + ); |
123 | 94 | }
|
124 | 95 | }
|
125 | 96 | </script>
|
126 |
| - |
127 |
| -<style lang="scss" scoped> |
128 |
| -.button--size-large + .button--size-small { |
129 |
| - margin-top: 1rem; |
130 |
| -} |
131 |
| -</style> |
0 commit comments