-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcreate.html
More file actions
174 lines (148 loc) · 6.99 KB
/
Copy pathcreate.html
File metadata and controls
174 lines (148 loc) · 6.99 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
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Create an Account</title>
<link href="https://cdn.jsdelivr.net/npm/boxicons@2.1.4/css/boxicons.min.css" rel="stylesheet">
<link rel="stylesheet" href="create.css">
</head>
<body>
<div class="form-container">
<img src="logo.png" alt="L'Arbre Envie Logo" class="logo">
<h1 class="form-title">Create an Account</h1>
<form id="signup-form" method="POST">
<div class="input-group">
<label for="username">Username</label>
<input type="text" id="username" name="username" placeholder="Enter your username" required>
</div>
<div class="input-group">
<label for="email">Email Address</label>
<input type="email" id="email" name="email" placeholder="Enter your email address" required>
</div>
<div class="input-group">
<label for="password">Password</label>
<div class="password-container">
<input type="password" id="password" name="password" placeholder="Enter your password" required>
<i class="bx bx-hide toggle-password"></i>
</div>
<small id="passwordError" class="error-message"></small>
<div id="passwordStrength" class="password-strength"></div>
</div>
<div class="input-group">
<label for="confirm-password">Confirm Password</label>
<div class="password-container">
<input type="password" id="confirm-password" name="confirm-password" placeholder="Confirm your password" required>
<i class="bx bx-hide toggle-password"></i>
</div>
<small id="confirmPasswordError" class="error-message"></small>
</div>
<button type="submit" class="form-button">Sign Up</button>
</form>
<p class="form-footer">Already have an account? <a href="connection.html" class="link">Log in</a></p>
</div>
<div id="theme-toggle">
<button id="theme-toggle-btn" title="Change Theme">
<i class="bx bx-sun"></i>
</button>
</div>
<script>
// Show/Hide passwords
document.querySelectorAll(".toggle-password").forEach(icon => {
icon.addEventListener("click", () => {
const input = icon.previousElementSibling;
input.type = input.type === "password" ? "text" : "password";
icon.classList.toggle("bx-hide");
icon.classList.toggle("bx-show");
});
});
// Validate password strength
function validatePassword(password) {
const minLength = 10;
const hasUpperCase = /[A-Z]/.test(password);
const hasLowerCase = /[a-z]/.test(password);
const hasSpecialChar = /[!@#$%^&*(),.?":{}|<>]/.test(password);
return password.length >= minLength && hasUpperCase && hasLowerCase && hasSpecialChar;
}
// Update password strength
function updatePasswordStrength(password) {
const strengthBar = document.getElementById('passwordStrength');
let strength = 0;
if (password.length >= 10) strength += 1; // Minimum length
if (/[A-Z]/.test(password)) strength += 1; // Uppercase
if (/[a-z]/.test(password)) strength += 1; // Lowercase
if (/[!@#$%^&*(),.?":{}|<>]/.test(password)) strength += 1; // Special character
// Update progress bar
strengthBar.style.width = (strength * 25) + '%';
strengthBar.className = 'password-strength'; // Reset
if (strength === 4) {
strengthBar.classList.add('valid');
} else if (strength >= 2) {
strengthBar.classList.add('medium');
} else {
strengthBar.classList.add('weak');
}
}
// Password input event
document.getElementById('password').addEventListener('input', (e) => {
updatePasswordStrength(e.target.value);
});
// Form validation
document.getElementById('signup-form').addEventListener('submit', async (e) => {
e.preventDefault();
const username = document.getElementById('username').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const confirmPassword = document.getElementById('confirm-password').value;
const passwordError = document.getElementById('passwordError');
const confirmPasswordError = document.getElementById('confirmPasswordError');
passwordError.textContent = '';
confirmPasswordError.textContent = '';
if (!validatePassword(password)) {
passwordError.textContent = 'Password must be at least 10 characters long and include an uppercase letter, a lowercase letter, and a special character.';
return;
}
if (password !== confirmPassword) {
confirmPasswordError.textContent = 'Passwords do not match.';
return;
}
try {
const checkResponse = await fetch('http://localhost:3000/check-user', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, email })
});
if (!checkResponse.ok) {
const { message } = await checkResponse.json();
alert(`Error: ${message}`);
return;
}
const response = await fetch('http://localhost:3000/register', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ username, email, password })
});
if (!response.ok) {
const { message } = await response.json();
alert(`Error: ${message}`);
} else {
window.location.href = 'connection.html';
}
} catch (error) {
alert(`Server connection error: ${error.message}`);
}
});
// Theme toggle
const themeToggleButton = document.getElementById("theme-toggle-btn");
const body = document.body;
themeToggleButton.addEventListener("click", () => {
body.classList.toggle("dark-theme");
const isDarkTheme = body.classList.contains("dark-theme");
localStorage.setItem("theme", isDarkTheme ? "dark-theme" : "light-theme");
});
if (localStorage.getItem("theme") === "dark-theme") {
body.classList.add("dark-theme");
}
</script>
</body>
</html>