-
Notifications
You must be signed in to change notification settings - Fork 18
/
SignUpView.vue
121 lines (102 loc) · 2.69 KB
/
SignUpView.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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
<script setup>
import { ref, computed } from "vue";
import BackendService from "@/BackendService";
import { useRouter } from "vue-router";
import { useMainStore } from "@/stores/main";
import VBtn from "@/components/common/VBtn.vue";
const router = useRouter();
const store = useMainStore();
const username = ref("");
const password = ref("");
const isLoading = ref(false);
const errorMessage = ref("");
const isValid = computed(() => {
return username.value.length && password.value.length;
});
async function onSubmit() {
isLoading.value = true;
errorMessage.value = "";
let res;
try {
res = await BackendService.signUp({
username: username.value,
password: password.value,
});
if (res.status !== 200) {
errorMessage.value = "Some fields are not valid.";
isLoading.value = false;
return;
}
const user = await res.json();
store.setCurrentUser(user);
const channelId = await store.init();
await router.push({ name: "channel", params: { channelId } });
} catch (_) {
errorMessage.value = "Something went wrong.";
isLoading.value = false;
}
}
</script>
<template>
<div class="d-flex align-items-center w-100">
<div class="form m-auto">
<form @submit.prevent="onSubmit">
<img class="mb-4" src="@/assets/logo.svg" width="72" height="57" />
<h1 class="h3 mb-3 fw-normal">Sign up</h1>
<div class="form-floating">
<input
type="text"
class="form-control"
id="floatingInput"
v-model="username"
placeholder="Username"
/>
<label for="floatingInput">Username*</label>
</div>
<div class="form-floating">
<input
type="password"
class="form-control"
id="floatingPassword"
v-model="password"
placeholder="Password"
/>
<label for="floatingPassword">Password*</label>
</div>
<v-btn
type="submit"
color="primary"
class="w-100 my-2 py-2"
:loading="isLoading"
:disabled="!isValid"
>
Sign up
</v-btn>
<div v-if="errorMessage" class="text-danger">
{{ errorMessage }}
</div>
</form>
<p class="mt-2">
Or <router-link :to="{ name: 'login' }">log in</router-link>.
</p>
</div>
</div>
</template>
<style scoped>
.form {
max-width: 330px;
padding: 1rem;
}
.form-floating:focus-within {
z-index: 2;
}
#floatingInput {
margin-bottom: -1px;
border-bottom-right-radius: 0;
border-bottom-left-radius: 0;
}
#floatingPassword {
border-top-left-radius: 0;
border-top-right-radius: 0;
}
</style>