Skip to content

Commit d9590a4

Browse files
author
Vianpyro
committed
Implement authentication forms with toggle between login and registration
1 parent 00a6a3f commit d9590a4

File tree

3 files changed

+151
-2
lines changed

3 files changed

+151
-2
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<template>
2+
<form id="login-form">
3+
<input type="email" id="login-email" name="email" placeholder="Email" required autofocus>
4+
<input type="password" id="login-password" name="password" placeholder="Password" required>
5+
<button type="submit">Login</button>
6+
</form>
7+
</template>
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<template>
2+
<form id="register-form">
3+
<input type="text" id="register-username" name="username" placeholder="Username" required>
4+
<input type="email" id="register-email" name="email" placeholder="Email" required>
5+
6+
<div>
7+
<input type="password" id="register-password" name="password" placeholder="Password" required>
8+
<input class="show-password-check" id="show-password-input" type="checkbox" tabindex="-1">
9+
<label class="show-password" for="show-password-input" title="Show Password"></label>
10+
<progress id="password-strength" class="hidden"></progress>
11+
</div>
12+
13+
<div>
14+
<input type="password" id="register-password-confirm" name="password-confirm"
15+
placeholder="Confirm password" required>
16+
<input class="show-password-check" id="show-password-confirm-input" type="checkbox" tabindex="-1">
17+
<label class="show-password" for="show-password-confirm-input" title="Show Password"></label>
18+
</div>
19+
20+
<button type="submit">Register</button>
21+
</form>
22+
</template>
23+
24+
<style scoped>
25+
#password-strength {
26+
appearance: none;
27+
height: 0.5rem;
28+
width: 100%;
29+
}
30+
</style>

pages/login.vue

Lines changed: 114 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,117 @@
11
<template>
2-
<div>
3-
Login
2+
<div id="authentication">
3+
<section id="login">
4+
<Login />
5+
<a id="go-to-login" @click="goToRegister">Don't have an account? <span class="link-color">Register</span></a>
6+
</section>
7+
<section id="register" class="hidden">
8+
<Register />
9+
<a id="go-to-register" @click="goToLogin">Already have an account? <span class="link-color">Login</span></a>
10+
</section>
411
</div>
512
</template>
13+
14+
<script setup>
15+
import Login from '@/components/authentication/Login.vue';
16+
import Register from '@/components/authentication/Register.vue';
17+
18+
const goToLogin = () => {
19+
document.getElementById('login').classList.remove('hidden');
20+
document.getElementById('register').classList.add('hidden');
21+
};
22+
23+
const goToRegister = () => {
24+
document.getElementById('login').classList.add('hidden');
25+
document.getElementById('register').classList.remove('hidden');
26+
};
27+
</script>
28+
29+
<style scoped>
30+
a {
31+
cursor: pointer;
32+
}
33+
34+
section {
35+
display: flex;
36+
flex-direction: column;
37+
align-items: center;
38+
}
39+
40+
.link-color {
41+
color: var(--color-primary);
42+
}
43+
44+
#authentication {
45+
display: flex;
46+
align-items: center;
47+
}
48+
49+
:deep(button[type="submit"]) {
50+
margin-top: 1rem;
51+
}
52+
53+
:deep(input[type="checkbox"]) {
54+
display: none;
55+
}
56+
57+
:deep(form) {
58+
display: flex;
59+
width: clamp(300px, 80%, 600px);
60+
flex-direction: column;
61+
border: 1px solid var(--background-color-secondary);
62+
padding: 2rem;
63+
border-radius: var(--border-radius);
64+
gap: 1rem;
65+
}
66+
67+
:deep(form>div) {
68+
display: flex;
69+
flex-direction: column;
70+
}
71+
72+
:deep(input) {
73+
padding: 0.5rem;
74+
border: none;
75+
border-radius: var(--border-radius);
76+
width: calc(100% - 0.5rem * 2);
77+
}
78+
79+
:deep(.password-input>label) {
80+
background-image: "url(../images/tabler--eye.svg)";
81+
height: 2rem;
82+
width: 2rem;
83+
background-repeat: no-repeat;
84+
background-size: contain;
85+
cursor: pointer;
86+
}
87+
88+
:deep(.show-password-check:checked+label.show-password) {
89+
background-image: "url(../images/tabler--eye-off.svg)";
90+
}
91+
92+
/* Pseudo-elements */
93+
94+
:deep(input:placeholder-shown) {
95+
border-bottom: 1px solid light-dark(black, white);
96+
}
97+
98+
:deep(
99+
input:user-valid,
100+
input.valid
101+
) {
102+
background-color: rgb(0 255 0 / 5%);
103+
border: 1px solid green;
104+
box-sizing: border-box;
105+
width: 100%;
106+
}
107+
108+
:deep(
109+
input:user-invalid,
110+
input.invalid
111+
) {
112+
background-color: rgb(255 0 0 / 5%);
113+
border: 1px solid red;
114+
box-sizing: border-box;
115+
width: 100%;
116+
}
117+
</style>

0 commit comments

Comments
 (0)