forked from Its-Aman-Yadav/Community-Site
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
263 lines (220 loc) · 7.37 KB
/
index.js
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
document.addEventListener('DOMContentLoaded', (event) => {
const navLinks = document.querySelectorAll('.nav-link');
const sections = document.querySelectorAll('.section');
// Function to remove active class from all links
const removeActiveClass = () => {
navLinks.forEach(link => {
link.classList.remove('active1');
});
};
// Function to add active class to the current link
const addActiveClass = (id) => {
const activeLink = document.querySelector(`.nav-link[href="#${id}"]`);
if (activeLink) {
activeLink.classList.add('active1');
}
};
// Intersection Observer to detect when sections are in view
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
removeActiveClass();
addActiveClass(entry.target.id);
}
});
}, { threshold: 0.5 }); // Adjust threshold to your needs
// Observe each section
sections.forEach(section => {
observer.observe(section);
});
// Smooth scrolling for links
navLinks.forEach(link => {
link.addEventListener('click', (event) => {
event.preventDefault();
document.querySelector(link.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});
});
const express = require("express");
const bodyParser = require("body-parser");
const nodemailer = require("nodemailer");
const app = express();
// Subscribe email validation
app.post("/validate-email", (req, res) => {
const { email } = req.body;
const emailRegex =
/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,}$/;
if (emailRegex.test(email)) {
res.status(200).json({ valid: true });
} else {
res.status(400).json({ valid: false, message: "Invalid email format" });
}
});
// Middleware
app.use(bodyParser.urlencoded({ extended: true }));
app.use(bodyParser.json());
// Routes
app.post("/send-email", (req, res) => {
const { name, email, message } = req.body;
// Create a transporter
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]", // Your email address
pass: "your_password", // Your email password or App Password
},
});
// Email options
const mailOptions = {
from: "[email protected]",
to: "[email protected]", // Recipient's email address
subject: "Contact Form Submission",
text: `Name: ${name}\nEmail: ${email}\nMessage: ${message}`,
};
// Send email
transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.error(error);
res.status(500).json({
success: false,
message: "Something went wrong. Please try again later.",
});
} else {
console.log("Email sent: " + info.response);
res
.status(200)
.json({ success: true, message: "Email sent successfully!" });
}
});
});
// Start server
const PORT = process.env.PORT || 5500;
app.listen(PORT, () => {
console.log(`Server is running on port ${PORT}`);
});
document.onselectstart = function () {
return false;
};
document.querySelectorAll(".accordion button").forEach((button) => {
button.addEventListener("click", () => {
const accordionItem = button.parentElement;
const content = button.nextElementSibling;
const expanded = accordionItem.getAttribute("aria-expanded") === "true";
document.querySelectorAll(".accordion-item").forEach((item) => {
item.setAttribute("aria-expanded", "false");
item.querySelector(".icon").textContent = "+";
item.querySelector(".accordion-content").style.maxHeight = "0";
});
if (!expanded) {
accordionItem.setAttribute("aria-expanded", "true");
button.querySelector(".icon").textContent = "-";
content.style.maxHeight = content.scrollHeight + "px";
} else {
accordionItem.setAttribute("aria-expanded", "false");
button.querySelector(".icon").textContent = "+";
content.style.maxHeight = "0";
}
});
s;
});
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyDCllQUQTUvYXL1Sr0fLwHsaKXrlyzVkz4",
authDomain: "login-with-firebase-data-72633.firebaseapp.com",
databaseURL:
"https://login-with-firebase-data-72633-default-rtdb.firebaseio.com",
projectId: "login-with-firebase-data-72633",
storageBucket: "login-with-firebase-data-72633.appspot.com",
messagingSenderId: "293527989470",
appId: "1:293527989470:web:ffa1a88282320903bd664f",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// Initialize Firebase Authentication and get a reference to the service
const auth = firebase.auth();
const database = firebase.database();
// Register function
function register() {
// Get all input fields
let email = document.getElementById("registerEmail").value;
let password = document.getElementById("registerPassword").value;
let full_name = document.getElementById("registerName").value;
// Validate input fields
if (!validate_email(email) || !validate_password(password)) {
alert("Email or Password is Outta Line!!");
return;
}
if (!validate_field(full_name)) {
alert("One or More Extra Fields is Outta Line!!");
return;
}
// Proceed with Auth
auth
.createUserWithEmailAndPassword(email, password)
.then(function () {
// Declare user variable
var user = auth.currentUser;
// Add this user to Firebase Database
var database_ref = database.ref();
// Create User data
var user_data = {
email: email,
full_name: full_name,
last_login: Date.now(),
};
// Push to Firebase Database
database_ref.child("users/" + user.uid).set(user_data);
// Done
alert("User Created!!");
})
.catch(function (error) {
// Firebase will use this to alert of its errors
var error_message = error.message;
alert(error_message);
});
}
// Login function
function login() {
// Get all input fields
let email = document.getElementById("email").value;
let password = document.getElementById("password").value;
// Validate input fields
if (!validate_email(email) || !validate_password(password)) {
alert("Email or Password is Outta Line!!");
return;
}
auth
.signInWithEmailAndPassword(email, password)
.then(function () {
// Declare user variable
var user = auth.currentUser;
// Add this user to Firebase Database
var database_ref = database.ref();
// Create User data
var user_data = {
last_login: Date.now(),
};
// Push to Firebase Database
database_ref.child("users/" + user.uid).update(user_data);
// Done
alert("User Logged In!!");
})
.catch(function (error) {
// Firebase will use this to alert of its errors
var error_message = error.message;
alert(error_message);
});
}
// Validate Functions
function validate_email(email) {
const expression = /^[^@]+@\w+(\.\w+)+\w$/;
return expression.test(email);
}
function validate_password(password) {
return password.length >= 6;
}
function validate_field(field) {
return field != null && field.length > 0;
}