Signup.vue
2.98 KB
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
<template>
<VaForm ref="form" @submit.prevent="submit">
<h1 class="font-semibold text-4xl mb-4">Sign up</h1>
<p class="text-base mb-4 leading-5">
Have an account?
<RouterLink :to="{ name: 'login' }" class="font-semibold text-primary">Login</RouterLink>
</p>
<VaInput
v-model="formData.email"
:rules="[(v) => !!v || 'Email field is required', (v) => /.+@.+\..+/.test(v) || 'Email should be valid']"
class="mb-4"
label="Email"
type="email"
/>
<VaValue v-slot="isPasswordVisible" :default-value="false">
<VaInput
ref="password1"
v-model="formData.password"
:rules="passwordRules"
:type="isPasswordVisible.value ? 'text' : 'password'"
class="mb-4"
label="Password"
messages="Password should be 8+ characters: letters, numbers, and special characters."
@clickAppendInner.stop="isPasswordVisible.value = !isPasswordVisible.value"
>
<template #appendInner>
<VaIcon
:name="isPasswordVisible.value ? 'mso-visibility_off' : 'mso-visibility'"
class="cursor-pointer"
color="secondary"
/>
</template>
</VaInput>
<VaInput
ref="password2"
v-model="formData.repeatPassword"
:rules="[
(v) => !!v || 'Repeat Password field is required',
(v) => v === formData.password || 'Passwords don\'t match',
]"
:type="isPasswordVisible.value ? 'text' : 'password'"
class="mb-4"
label="Repeat Password"
@clickAppendInner.stop="isPasswordVisible.value = !isPasswordVisible.value"
>
<template #appendInner>
<VaIcon
:name="isPasswordVisible.value ? 'mso-visibility_off' : 'mso-visibility'"
class="cursor-pointer"
color="secondary"
/>
</template>
</VaInput>
</VaValue>
<div class="flex justify-center mt-4">
<VaButton class="w-full" @click="submit"> Create account</VaButton>
</div>
</VaForm>
</template>
<script lang="ts" setup>
import { reactive } from 'vue'
import { useRouter } from 'vue-router'
import { useForm, useToast } from 'vuestic-ui'
const { validate } = useForm('form')
const { push } = useRouter()
const { init } = useToast()
const formData = reactive({
email: '',
password: '',
repeatPassword: '',
})
const submit = () => {
if (validate()) {
init({
message: "You've successfully signed up",
color: 'success',
})
push({ name: 'dashboard' })
}
}
const passwordRules: ((v: string) => boolean | string)[] = [
(v) => !!v || 'Password field is required',
(v) => (v && v.length >= 8) || 'Password must be at least 8 characters long',
(v) => (v && /[A-Za-z]/.test(v)) || 'Password must contain at least one letter',
(v) => (v && /\d/.test(v)) || 'Password must contain at least one number',
(v) => (v && /[!@#$%^&*(),.?":{}|<>]/.test(v)) || 'Password must contain at least one special character',
]
</script>