-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSignUp.html
More file actions
154 lines (141 loc) · 6.91 KB
/
SignUp.html
File metadata and controls
154 lines (141 loc) · 6.91 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Visualizing Math</title>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@100;200;300;400;600;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.7.1/css/all.min.css" integrity="sha512-5Hs3dF2AEPkpNAR7UiOHba+lRSJNeM2ECkwxUIxC1Q/FLycGTbNapWXB4tP889k5T5Ju8fs4b1P5z/iB4nMfSQ==" crossorigin="anonymous" referrerpolicy="no-referrer" />
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<link href='https://unpkg.com/boxicons@2.1.4/css/boxicons.min.css' rel='stylesheet'>
</head>
<body>
<section class="sub-header">
<nav>
<a href="index.html"><img src="images/logo.png" alt="Logo"></a>
<div class="nav-links" id="navLinks">
<i class="fas fa-xmark" onclick="hideMenu()"></i>
<ul>
<li><a href="index.html">HOME</a></li>
<li><a href="about.html">ABOUT</a></li>
<li><a href="SignUp.html">SIGN UP</a></li>
<li id="login-nav"><a href="Login.html">LOG IN</a></li>
<li id="logout-nav" style="display: none;"><a href="#" onclick="logout()">LOG OUT</a></li>
<li><a href="Algebra.html">ALGEBRA</a></li>
<li><a href="Geometry.html">GEOMETRY</a></li>
</ul>
</div>
<i class="fas fa-bars" onclick="showMenu()"></i>
</nav>
<h1>Sign Up</h1>
</section>
<div class="wrapper">
<div class="form-box">
<div class="register-container" id="register">
<div class="top">
<span>Have an account? <a href="Login.html">Login</a></span>
</div>
<div class="two-forms">
<div class="input-box">
<input type="text" id="firstname" class="input-field" placeholder="Firstname">
<i class="bx bx-user"></i>
</div>
<div class="input-box">
<input type="text" id="lastname" class="input-field" placeholder="Lastname">
<i class="bx bx-user"></i>
</div>
</div>
<div class="input-box">
<input type="email" id="email" class="input-field" placeholder="Email">
<i class="bx bx-envelope"></i>
</div>
<div class="input-box">
<input type="password" id="password" class="input-field" placeholder="Password">
<i class="bx bx-lock-alt"></i>
</div>
<div class="input-box">
<input type="submit" id="submit" class="submit" value="Register">
</div>
<div class="two-col">
<div class="one">
<input type="checkbox" id="register-check">
<label for="register-check"> Remember Me</label>
</div>
</div>
</div>
</div>
</div>
<!-- Firebase JS SDK -->
<script type="module">
// Import Firebase services using Firebase 9+ modular SDK
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-app.js";
import { getAuth } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-auth.js";
import { getFirestore } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-firestore.js";
import { createUserWithEmailAndPassword, updateProfile } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-auth.js";
import { doc, setDoc } from "https://www.gstatic.com/firebasejs/9.22.2/firebase-firestore.js";
// Your Firebase configuration (replace with your actual config values)
const firebaseConfig = {
apiKey: "AIzaSyAMPqEC7vmFh0Sm22KMmAVxaS_F7CI_YRM",
authDomain: "visualizing-math.firebaseapp.com",
projectId: "visualizing-math",
storageBucket: "visualizing-math.appspot.com",
messagingSenderId: "128503124502",
appId: "1:128503124502:web:a5a5c786244e25c0af9b37",
measurementId: "G-7LGGDVLGLP"
};
// Initialize Firebase app
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
// Handle the register action
document.getElementById('submit').addEventListener('click', async function(e) {
e.preventDefault();
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const firstname = document.getElementById('firstname').value;
const lastname = document.getElementById('lastname').value;
if (!firstname || !lastname || !email || !password) {
alert("All fields are required.");
return;
}
// Simple email validation
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
if (!emailRegex.test(email)) {
alert("Please enter a valid email address.");
return;
}
// Password validation
if (password.length < 6) {
alert("Password must be at least 6 characters long.");
return;
}
try {
// Register new user with email and password
const userCredential = await createUserWithEmailAndPassword(auth, email, password);
// Update user profile with first and last name
await updateProfile(userCredential.user, {
displayName: `${firstname} ${lastname}`
});
// ✅ Write user data to Firestore before redirect
await setDoc(doc(db, "users", userCredential.user.uid), {
firstname: firstname,
lastname: lastname,
email: email,
createdAt: new Date()
});
alert("Sign up successful!");
window.location.href = "Login.html";
} catch (error) {
if (error.code === 'auth/email-already-in-use') {
alert("This email is already registered. Please use a different email.");
} else {
alert("Error: " + error.message);
}
}
});
</script>
</body>
</html>