Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Email functionality #290

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions backend/app.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const express = require('express');
const app = express();

const emailRouter = require("./router/EmailRoute.js");
const authRouter = require('./router/authRoute.js');
const databaseconnect = require('./config/databaseConfig.js');
const cookieParser = require('cookie-parser');
Expand All @@ -16,7 +16,7 @@ app.use(cors({ origin: [process.env.CLIENT_URL], credentials: true })); //Third-

// Auth router
app.use('/auth', authRouter);

app.use("/email", emailRouter);
app.use('/', (req, res) => {
res.status(200).json({ data: 'JWTauth server ;)' });
});
Expand Down
33 changes: 33 additions & 0 deletions backend/controller/EmailController.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const nodemailer = require("nodemailer");

async function SendEmailController(req, resp) {
const transporter = nodemailer.createTransport({
service: "gmail",
auth: {
user: "[email protected]", // youe email
pass: "password", // your password
},
});

const mailOptions = {
from: "[email protected]",
to: "[email protected]", // email where you want to receive the message
subject: "New From Collect your GamingTools",
text: `
Name: ${req.body.Name}
Email: ${req.body.Email}
Message: ${req.body.Message}`,
};

transporter.sendMail(mailOptions, (error, info) => {
if (error) {
console.log("Error sending email: " + error);
resp.status(500).send("Error sending email");
} else {
console.log("Email sent: " + info.response);
resp.status(200).send("Form data sent successfully");
}
});
}

module.exports = { SendEmailController };
1 change: 1 addition & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"crypto": "^1.0.1",
"dotenv": "^16.4.5",
"email-validator": "^2.0.4",
"nodemailer": "^6.9.15",
"express": "^4.21.0",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.7.0",
Expand Down
8 changes: 8 additions & 0 deletions backend/router/EmailRoute.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
const express = require("express");
const emailRouter = express.Router();

const { SendEmailController } = require("../controller/EmailController");

emailRouter.post("/SendEmail", SendEmailController);

module.exports = emailRouter;
165 changes: 97 additions & 68 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,96 +2,125 @@ var menuList = document.getElementById("menuList");
menuList.style.maxHeight = "0px";

function toggleMenu() {
if (menuList.style.maxHeight == "0px") {
menuList.style.maxHeight = "160px";
} else {
menuList.style.maxHeight = "0px";
}
}
window.onscroll = function() {
updateProgressBar();
};


function updateProgressBar() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight = document.documentElement.scrollHeight - document.documentElement.clientHeight;
var scrollPercent = (scrollTop / scrollHeight) * 100;

document.getElementById("progressBar").style.width = scrollPercent + "%";
if (menuList.style.maxHeight == "0px") {
menuList.style.maxHeight = "160px";
} else {
menuList.style.maxHeight = "0px";
}

document.addEventListener('DOMContentLoaded', () => {
console.log("Website loaded successfully!");
}
window.onscroll = function () {
updateProgressBar();
};

function updateProgressBar() {
var scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
var scrollHeight =
document.documentElement.scrollHeight -
document.documentElement.clientHeight;
var scrollPercent = (scrollTop / scrollHeight) * 100;

document.getElementById("progressBar").style.width = scrollPercent + "%";
}

document.addEventListener("DOMContentLoaded", () => {
console.log("Website loaded successfully!");
});

// Show or hide the scroll-top button based on scroll position
window.addEventListener('scroll', function() {
const scrollTopButton = document.querySelector('.scroll-top');
if (window.pageYOffset > 300) {
scrollTopButton.style.display = 'block';
} else {
scrollTopButton.style.display = 'none';
}
window.addEventListener("scroll", function () {
const scrollTopButton = document.querySelector(".scroll-top");
if (window.pageYOffset > 300) {
scrollTopButton.style.display = "block";
} else {
scrollTopButton.style.display = "none";
}
});

// Smooth scroll to top when the button is clicked
function scrollToTop() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
window.scrollTo({
top: 0,
behavior: "smooth",
});
}

function toggleTheme() {
const body = document.body;
const themeToggle = document.getElementById('theme-toggle');
body.classList.toggle('dark-mode', themeToggle.checked);
const body = document.body;
const themeToggle = document.getElementById("theme-toggle");
body.classList.toggle("dark-mode", themeToggle.checked);

// Save the user's preference in localStorage
if (themeToggle.checked) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
// Save the user's preference in localStorage
if (themeToggle.checked) {
localStorage.setItem("theme", "dark");
} else {
localStorage.setItem("theme", "light");
}
}

// Load theme from localStorage on page load
window.onload = () => {
const savedTheme = localStorage.getItem('theme');
const themeToggle = document.getElementById('theme-toggle');
if (savedTheme === 'dark') {
document.body.classList.add('dark-mode');
themeToggle.checked = true;
}
const savedTheme = localStorage.getItem("theme");
const themeToggle = document.getElementById("theme-toggle");
if (savedTheme === "dark") {
document.body.classList.add("dark-mode");
themeToggle.checked = true;
}
};

//function to remove sidebar upon clicking close button
function toggleSidebar() {
var sidebar = document.getElementById("SideBar");
var sidebarContent = document.getElementById("sidebar-content");
if (sidebar) {
// Remove the sidebar element and its content
sidebar.remove();
sidebarContent.remove();
var sidebar = document.getElementById("SideBar");
var sidebarContent = document.getElementById("sidebar-content");
if (sidebar) {
// Remove the sidebar element and its content
sidebar.remove();
sidebarContent.remove();
} else {
console.error("Sidebar element not found");
}
}

function performSearch() {
let searchTerm = document.getElementById("search-input").value.toLowerCase();
console.log(searchTerm);
let cards = document.querySelectorAll(".row");

cards.forEach(function (card) {
let cardHeading = card
.querySelector(".card-heading")
.innerText.toLowerCase();

// Check if the search term is in the card heading or description
if (cardHeading.includes(searchTerm)) {
card.style.display = "block"; // Show the card
} else {
console.error("Sidebar element not found");
card.style.display = "none"; // Hide the card
}
};
});
}

function performSearch(){
let searchTerm = document.getElementById('search-input').value.toLowerCase();
console.log(searchTerm);
let cards = document.querySelectorAll('.row');

cards.forEach(function (card) {
let cardHeading = card.querySelector('.card-heading').innerText.toLowerCase();

// Check if the search term is in the card heading or description
if (cardHeading.includes(searchTerm)) {
card.style.display = "block"; // Show the card
} else {
card.style.display = "none"; // Hide the card
}
async function SendEmail(e) {
e.preventDefault();
const Name = document.getElementById("name").value;
const Email = document.getElementById("email").value;
const Message = document.getElementById("message").value;

try {
const response = await fetch("http://localhost:5000/email/SendEmail", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ Name, Email, Message }),
});

if (response.ok) {
alert("Email sent successfully!");
} else {
alert("Error sending email");
}
} catch (error) {
console.error("Error:", error);
alert("An error occurred while sending the email.");
}
}