-
Notifications
You must be signed in to change notification settings - Fork 2
/
studentsignup.html
158 lines (139 loc) · 6.61 KB
/
studentsignup.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DEI ENGINEERING - SignUP</title>
<link rel="icon" href="img/about122.png" type="image/x-icon">
<!-- Stylesheets -->
<link rel="stylesheet" href="css/home.css">
<link rel="stylesheet" href="css/contact.css">
<link rel="stylesheet" href="css/login.css">
<!-- Add these lines to include Firebase SDK -->
<script src="https://www.gstatic.com/firebasejs/8.7.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.7.0/firebase-auth.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.7.0/firebase-firestore.js"></script>
</head>
<body>
<!-- navbar -->
<nav class="navbar"></nav>
<main-section class="box-form">
<div class="left">
<div class="overlay"></div>
</div>
<div class="right">
<div class="login-container">
<form id="signupForm" class="login-form">
<h2 class="header">Student-Sign UP</h2>
<div class="form-group inputs">
<label class="label1" for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group inputs">
<label class="label1" for="rollNo">Roll No:</label>
<input type="number" id="rollNo" name="rollNo" required>
</div>
<div class="form-group inputs">
<label class="label1" for="name">Course:</label>
<input type="text" id="course" name="course" required>
</div>
<div class="form-group inputs">
<label class="label1" for="name">Branch:</label>
<input type="text" id="branch" name="branch" required>
</div>
<div class="form-group inputs">
<label class="label1" for="email">Email Address:</label>
<input type="text" id="email" name="email" required>
</div>
<div class="form-group inputs">
<label class="label2" for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<div class="form-group inputs">
<label class="label2" for="confirmpassword"> Confirm Password:</label>
<input type="password" id="confirmpassword" name="confirmpassword" required>
</div>
<div class="form-group">
<button type="submit">Sign Up</button>
</div>
<div class="form-group">
<p>Already Registered? <a href="login.html">Login</a></p>
</div>
<div class="form-message" id="formMessage"></div>
</form>
</div>
</div>
</main-section>
<!-- footer -->
<div class="footer-main"></div>
<script src="js/nav.js"></script>
<script src="js/footer.js"></script>
<script>
// Replace with your Firebase project configuration
var firebaseConfig = {
apiKey: "AIzaSyCu3Jlxe8Ao3SphePEMG6qXE1f1_YYjb7o",
authDomain: "deipage-detd.firebaseapp.com",
projectId: "deipage-detd",
storageBucket: "deipage-detd.appspot.com",
messagingSenderId: "830390951653",
appId: "1:830390951653:web:92ad43a7a52c844c18be0c",
measurementId: "G-QFX4F832FE"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
const auth = firebase.auth();
const firestore = firebase.firestore();
// Function to handle form submission
function signUp() {
// Retrieve form values
const name = document.getElementById('name').value;
const rollNo = document.getElementById('rollNo').value;
const email = document.getElementById('email').value;
const password = document.getElementById('password').value;
const course = document.getElementById('course').value;
const branch = document.getElementById('branch').value;
const confirmPassword = document.getElementById('confirmpassword').value;
// Check if passwords match
if (password !== confirmPassword) {
document.getElementById('formMessage').innerText = "Passwords do not match";
return;
}
// Create a new user with email and password
auth.createUserWithEmailAndPassword(email, password)
.then((userCredential) => {
// Signed up successfully
const user = userCredential.user;
console.log('User signed up:', user);
// Save user data in Firestore
firestore.collection('students').doc(user.uid).set({
name: name,
rollNo: rollNo,
email: email,
course: course,
branch: branch
})
.then(() => {
console.log('User data saved in Firestore');
window.location.href = 'studentdashboard.html';
// You can redirect to another page or perform additional actions here
})
.catch((error) => {
console.error('Error saving user data in Firestore:', error);
document.getElementById('formMessage').innerText = "Error saving user data in Firestore";
});
})
.catch((error) => {
// Handle errors during signup
const errorMessage = error.message;
console.error('Signup error:', errorMessage);
document.getElementById('formMessage').innerText = errorMessage;
});
}
// Attach the signUp function to the form submission
document.getElementById('signupForm').addEventListener('submit', function (event) {
event.preventDefault(); // Prevent default form submission
signUp(); // Call the signUp function
});
</script>
</body>
</html>