-
Notifications
You must be signed in to change notification settings - Fork 0
/
Student-Registration.html
433 lines (384 loc) · 13.8 KB
/
Student-Registration.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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<title>Dynamic User Registration</title>
<style>
body {
background-color: #f0f0f0;
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.main-content {
display: flex;
flex-wrap: wrap;
justify-content: space-around;
padding: 20px;
}
.registration-form,
.live-camera-container {
width: 100%;
max-width: 500px;
background-color: #fff;
padding: 20px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
margin: 20px;
}
.registration-form h1,
.live-camera-container h1 {
font-size: 24px;
margin-bottom: 20px;
}
.form-group {
width: 100%;
margin-bottom: 15px;
}
.form-group label {
font-weight: bold;
display: block;
margin-bottom: 5px;
}
.form-group input,
.form-group select {
width: 100%;
padding: 10px;
font-size: 16px;
border: 1px solid #ccc;
border-radius: 5px;
box-sizing: border-box;
}
button {
width: 100%;
background-color: #0056b3;
color: #fff;
font-size: 18px;
padding: 10px 20px;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
button:hover {
background-color: #004494;
}
.message {
margin-top: 10px;
color: #d9534f;
font-size: 16px;
text-align: center;
}
.video-container img {
width: 100%;
height: auto;
border-radius: 8px;
margin-bottom: 15px;
}
.video-container {
position: relative;
display: flex;
justify-content: center;
align-items: center;
margin-bottom: 20px;
}
@media screen and (min-width: 768px) {
.registration-form,
.live-camera-container {
width: 45%;
}
}
</style>
</head>
<body>
<!-- Navbar -->
<nav class="navbar">
<div class="logo"><a href="index.html">FaceSnap</a></div>
<div class="navbar-links">
<a href="index.html">Home</a>
<a href="#about">About</a>
<a href="#contact">Contact</a>
<a href="login.html">Account</a>
<a href="/Teacher-info.html">Teacher Info</a>
<a href="/FaceSnap/subject.html">Manage Subject</a>
<a href="/FaceSnap/attendance-list.html">Attendance List</a>
</div>
<div id="mobile-toggle" class="icon">☰</div>
</nav>
<!-- Main Content -->
<div class="main-content">
<!-- Left Side - User Registration Form -->
<div class="registration-form">
<h1>User Registration</h1>
<form id="registration-form">
<div class="form-group">
<label for="userType">User Type:</label>
<select id="userType" name="userType" required onchange="updateFormFields()">
<option value="">Select User Type</option>
<option value="student">Student</option>
<option value="teacher">Teacher</option>
<option value="admin">Admin</option>
</select>
</div>
<div id="dynamic-fields">
<!-- Dynamic fields will be inserted here based on the selected user type -->
</div>
<button type="submit">Register</button>
<p class="message" id="response-message"></p>
</form>
</div>
<!-- Right Side - Live Camera Capture -->
<div class="live-camera-container">
<h1>Live Camera</h1>
<div class="video-container">
<img src="http://192.168.158.246:5001/video_feed" id="videoStream" alt="Video Feed">
</div>
<button id="capture-button">Capture Image</button>
<canvas id="canvas" style="display: none;"></canvas>
</div>
</div>
<!-- Footer -->
<footer class="footer">
<div class="footer-left">
<a href="https://www.linkedin.com/in/shubham-choudhary-shubh/" class="social-icon"><i
class="fab fa-linkedin-in"></i></a>
<a href="https://github.com/ShubhamChoudharyShubh" class="social-icon"><i class="fab fa-github"></i></a>
<a href="https://www.instagram.com/shubhamchoudharyshubh/" class="social-icon"><i
class="fab fa-instagram"></i></a>
<a href="https://www.linkedin.com/in/shubham-choudhary-shubh/" class="social-icon"><i
class="fab fa-facebook"></i></a>
</div>
<div class="footer-right">
<p class="f-para">Copyright © 2024, FaceSnap.in all rights reserved</p>
</div>
</footer>
<script>
let imgshubham
document.addEventListener('DOMContentLoaded', function () {
const img = document.getElementById('videoStream');
const canvas = document.getElementById('canvas');
const ctx = canvas.getContext('2d');
const responseMessage = document.getElementById('response-message');
const captureButton = document.getElementById('capture-button');
// Attempt to reload the video feed if it stops or fails to load
img.onerror = function () {
console.log('Error loading video feed, attempting to reconnect...');
setTimeout(() => {
img.src = img.src.split('?')[0] + '?' + new Date().getTime();
}, 1000);
};
// Function to capture an image from the video feed
function captureImage() {
// Ensure the canvas dimensions match the current video/image dimensions
canvas.width = img.width;
canvas.height = img.height;
ctx.drawImage(img, 0, 0, canvas.width, canvas.height);
return canvas.toDataURL('image/jpeg');
}
// Attach event to the "Capture Image" button
captureButton.addEventListener('click', function () {
console.log("Button clicked")
const userType = document.getElementById('userType').value
if (userType === '') {
alert("user is not select please select user")
return;
}
try{
fetch('http://192.168.158.246:5000/gen_face', {
method: 'POST', // Specifies the request method
headers: {
'Content-Type': 'application/json' // Specifies that the body of the request is JSON
},
body: JSON.stringify({
type: userType,
}) // Converts the JavaScript object into a JSON string
})
.then((response) => {
console.log("Hello")
return response.json()
})
.then((response)=>{
console.log({CAT:response})
response.forEach(({ data, image }) => {
if(!data)
{
console.log("Image:", image);
var input = document.createElement('input');
input.type = 'image';
// Unique ID for each input field
input.src='data:image/jpeg;base64,' + image
// Append input field to the container
imgshubham=image
console.log(input)
document.getElementById('input').appendChild(input);
console.log("It is reached here")
document.getElementById('jai').innerHTML = "image is captured"
}else{
alert("you already exist")
}
return ;
});
}) // Parses the JSON response
.catch(error => {
console.error('Error:', error); // Handles any errors that occur during the fetch
});
}catch(e)
{
console.log(e)
}
});
// Function to update form fields based on the selected user type
// Function to handle form submission
function submitForm(event) {
event.preventDefault(); // Prevent default form submission behavior
// Retrieve form data
const form = event.target;
const formData = new FormData(form);
const userType = document.getElementById('userType').value;
console.log({event:event.target})
// Convert form data to JSON
const jsonData = {};
formData.forEach((value, key) => {
jsonData[key] = value;
});
jsonData.image=imgshubham
console.log({jsonData})
// Add image data to the JSON object
// const capturedImage = captureImage();
// if (capturedImage) {
// jsonData['image'] = capturedImage;
// } else {
// console.error('Failed to capture image from video feed.');
// responseMessage.textContent = "Failed to capture image from video feed.";
// responseMessage.style.color = "red";
// return;
// }
// Define the URL of the POST API
const apiUrl = `http://192.168.158.246:5000/register/${userType}`; // Replace with your API URL
console.log({win:window.top.location})
// Define fetch options
const options = {
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(jsonData)
};
// Make POST request
fetch(apiUrl, options)
.then(response => response.json())
.then(data => {
if (data.message === "User already registered") {
responseMessage.textContent = "User already registered";
responseMessage.style.color = "red";
} else if (data.message === "Registration successful") {
responseMessage.textContent = "Successfully registered";
responseMessage.style.color = "green";
} else {
responseMessage.textContent = "Success: " + data.message;
responseMessage.style.color = "green";
}
})
.catch(error => {
console.error('Error during registration:', error);
responseMessage.textContent = "Registration failed: " + error;
responseMessage.style.color = "red";
});
}
// Add event listener for form submission
const registrationForm = document.getElementById('registration-form');
registrationForm.addEventListener('submit', submitForm);
// Initialize form with the default user type selection
updateFormFields();
});
// Function to dynamically update form fields
function updateFormFields() {
const userType = document.getElementById('userType').value;
const dynamicFields = document.getElementById('dynamic-fields');
dynamicFields.innerHTML = ''; // Clear previous fields
if (userType === 'student') {
dynamicFields.innerHTML = `
<div class="form-group">
<label for="id">ID:</label>
<input type="text" id="id" name="id" required>
</div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="year">Year:</label>
<input type="text" id="year" name="year" required>
</div>
<div class="form-group">
<label for="semester">Semester:</label>
<input type="text" id="semester" name="semester" required>
</div>
<div class="form-group">
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" required>
</div>
<div class="form-group">
<label for="branch">Branch:</label>
<input type="text" id="branch" name="branch" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div id='input' class="form-group">
<label for="image">Image:</label>
</div>
`;
} else if (userType === 'teacher') {
dynamicFields.innerHTML = `
<div class="form-group">
<label for="id">ID:</label>
<input type="text" id="id" name="id" required>
</div>
<div class="form-group">
<label for="name">Name:</label>
<input type="text" id="name" name="name" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="mobile">Mobile:</label>
<input type="text" id="mobile" name="mobile" required>
</div>
<div id='input' class="form-group">
<label for="image">Image:</label>
</div>
`;
} else if (userType === 'admin') {
dynamicFields.innerHTML = `
<div class="form-group">
<label for="username">Username:</label>
<input type="text" id="username" name="username" required>
</div>
<div class="form-group">
<label for="email">Email:</label>
<input type="email" id="email" name="email" required>
</div>
<div class="form-group">
<label for="mobileNumber">Mobile Number:</label>
<input type="text" id="mobileNumber" name="mobileNumber" required>
</div>
<div class="form-group">
<label for="password">Password:</label>
<input type="password" id="password" name="password" required>
</div>
<div id='input' class="form-group">
<label for="image">Image:</label>
</div>
`;
}
}
</script>
</body>
</html>