From 09bbf1106a807362862bd9976b57568bd29e7b0d Mon Sep 17 00:00:00 2001 From: Ayush Date: Fri, 11 Oct 2024 08:13:28 +0530 Subject: [PATCH 1/2] Email --- backend/controller/EmailController.js | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 backend/controller/EmailController.js diff --git a/backend/controller/EmailController.js b/backend/controller/EmailController.js new file mode 100644 index 00000000..3b6dd152 --- /dev/null +++ b/backend/controller/EmailController.js @@ -0,0 +1,33 @@ +const nodemailer = require("nodemailer"); + +async function SendEmailController(req, resp) { + const transporter = nodemailer.createTransport({ + service: "gmail", + auth: { + user: "yourEmail@gmail.com", // youe email + pass: "password", // your password + }, + }); + + const mailOptions = { + from: "yourEmail@gmail.com", + to: "yourEmail@gmail.com", // 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 }; From fe17381eccf207e9b218d48853112f690ec4a52f Mon Sep 17 00:00:00 2001 From: Ayush Date: Fri, 11 Oct 2024 08:31:31 +0530 Subject: [PATCH 2/2] Email --- backend/app.js | 4 +- backend/package.json | 1 + backend/router/EmailRoute.js | 8 ++ script.js | 165 ++++++++++++++++++++--------------- 4 files changed, 108 insertions(+), 70 deletions(-) create mode 100644 backend/router/EmailRoute.js diff --git a/backend/app.js b/backend/app.js index 2240a583..84d8ceb0 100644 --- a/backend/app.js +++ b/backend/app.js @@ -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'); @@ -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 ;)' }); }); diff --git a/backend/package.json b/backend/package.json index 1a75df87..2d1344de 100644 --- a/backend/package.json +++ b/backend/package.json @@ -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", diff --git a/backend/router/EmailRoute.js b/backend/router/EmailRoute.js new file mode 100644 index 00000000..332afd30 --- /dev/null +++ b/backend/router/EmailRoute.js @@ -0,0 +1,8 @@ +const express = require("express"); +const emailRouter = express.Router(); + +const { SendEmailController } = require("../controller/EmailController"); + +emailRouter.post("/SendEmail", SendEmailController); + +module.exports = emailRouter; \ No newline at end of file diff --git a/script.js b/script.js index 0c92f5d9..a4d5892b 100644 --- a/script.js +++ b/script.js @@ -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."); + } }