forked from rajpra808/Library-Management-System
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuser_registration.html
More file actions
137 lines (118 loc) · 4.81 KB
/
user_registration.html
File metadata and controls
137 lines (118 loc) · 4.81 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>User Registration</title>
<!-- Firebase SDK with modules support -->
<script type="module">
// Import Firebase SDK
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-app.js";
import { getAuth, createUserWithEmailAndPassword } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-auth.js";
import { getFirestore, doc, setDoc } from "https://www.gstatic.com/firebasejs/9.6.1/firebase-firestore.js";
// Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyBA2O5kze6cSrMqrUpDYoP5KZepBsNEa4k",
authDomain: "library-management-syste-37dc2.firebaseapp.com",
databaseURL: "https://library-management-syste-37dc2-default-rtdb.firebaseio.com",
projectId: "library-management-syste-37dc2",
storageBucket: "library-management-syste-37dc2.firebasestorage.app",
messagingSenderId: "962676782645",
appId: "1:962676782645:web:c008daf774bcee5a80e37c",
measurementId: "G-NZ9VJF0LJ2"
};
// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const db = getFirestore(app);
// Register User Function
document.getElementById("registration-form").addEventListener("submit", function(e) {
e.preventDefault();
// Get input values
var name = document.getElementById("usr_name").value;
var email = document.getElementById("usr_email").value;
var password = document.getElementById("usr_pass").value;
var rollNumber = document.getElementById("usr_roll").value;
var dateOfBirth = document.getElementById("usr_dob").value;
// Validate inputs
if (!name || !email || !password || !rollNumber || !dateOfBirth) {
alert("All fields are required!");
return;
}
// Firebase Authentication (Create a user with email and password)
createUserWithEmailAndPassword(auth, email, password)
.then((userCredential) => {
// Successfully created user
const user = userCredential.user;
// Store user data in Firestore
return setDoc(doc(db, "users", rollNumber), {
name: name,
email: email,
rollNumber: rollNumber,
dob: dateOfBirth,
books: [] // Initially empty array for borrowed books
});
})
.then(() => {
alert("User registered successfully!");
// Optionally, redirect to the login page or user portal
window.location = "user_portal.html"; // Redirect after successful registration
})
.catch((error) => {
console.error("Error during registration: ", error.message);
alert("Error: " + error.message);
});
});
</script>
<style>
body {
font-family: Arial, sans-serif;
padding: 20px;
background-color: #f4f4f9;
}
form {
max-width: 400px;
margin: 0 auto;
padding: 50px;
background: #ffffff;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
}
input {
width: 100%;
padding: 10px;
margin: 10px 0;
border-radius: 4px;
border: 1px solid #ccc;
}
button {
padding: 10px 15px;
background-color: #4CAF50;
color: white;
border: none;
border-radius: 4px;
cursor: pointer;
width: 100%;
}
button:hover {
background-color: #45a049;
}
h2 {
text-align: center;
color: #333;
}
</style>
</head>
<body>
<h2>User Registration</h2>
<form id="registration-form">
<input type="text" id="usr_name" placeholder="Full Name" required>
<input type="email" id="usr_email" placeholder="Email Address" required>
<input type="password" id="usr_pass" placeholder="Password" required>
<input type="text" id="usr_roll" placeholder="Roll Number" required>
<input type="date" id="usr_dob" placeholder="Date of Birth" required>
<button type="submit">Register</button>
<p class="message">Already registered? <a href="usr_login.html">Sign In</a></p>
</form>
</body>
</html>