From 488738b6d241c218a8fa10676556516827738658 Mon Sep 17 00:00:00 2001 From: Tina Date: Tue, 29 Oct 2024 13:21:28 +0530 Subject: [PATCH 1/2] Multi-Language Support Using Language Translator --- frontend/src/App.jsx | 5 +- frontend/src/Pages/GoogleTranslate.jsx | 148 +++++++++++++++++++++++++ frontend/src/Pages/Herosection.jsx | 10 +- 3 files changed, 161 insertions(+), 2 deletions(-) create mode 100644 frontend/src/Pages/GoogleTranslate.jsx diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index cc51905..65fa1b4 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -16,6 +16,7 @@ import NotificationPage from "./Pages/notification"; import Chatbot from "./components/chatbot"; import ContactUs from "./Pages/ContactUs"; import Settings from "./components/Settings"; +import GoogleTranslate from "./Pages/GoogleTranslate"; import Help from "./components/help"; import Contributor from "./Pages/contributor"; import Payment from "./Pages/Payment"; @@ -44,6 +45,7 @@ function App() { } /> } /> } /> + } /> } /> } /> } /> @@ -51,7 +53,8 @@ function App() { } /> } /> } /> - } /> {/* Restored PrivacyPolicy */} + } />{" "} + {/* Restored PrivacyPolicy */} } /> {/* Added User */} } /> diff --git a/frontend/src/Pages/GoogleTranslate.jsx b/frontend/src/Pages/GoogleTranslate.jsx new file mode 100644 index 0000000..b5df449 --- /dev/null +++ b/frontend/src/Pages/GoogleTranslate.jsx @@ -0,0 +1,148 @@ +import React, { useEffect } from "react"; + +const GoogleTranslate = () => { + useEffect(() => { + window.googleTranslateInit = () => { + if (!window.google?.translate?.TranslateElement) { + setTimeout(window.googleTranslateInit, 100); + } else { + new window.google.translate.TranslateElement( + { + pageLanguage: "en", + includedLanguages: + "en,hi,pa,sa,mr,ur,bn,es,ja,ko,zh-CN,es,nl,fr,de,it,ta,te", + layout: + window.google.translate.TranslateElement.InlineLayout.HORIZONTAL, + defaultLanguage: "en", + autoDisplay: false, + }, + "google_element" + ); + } + cleanUpGadgetText(); + }; + + const loadGoogleTranslateScript = () => { + if (!document.getElementById("google_translate_script")) { + const script = document.createElement("script"); + script.type = "text/javascript"; + script.src = + "https://translate.google.com/translate_a/element.js?cb=googleTranslateInit"; + script.id = "google_translate_script"; + script.onerror = () => + console.error("Error loading Google Translate script"); + document.body.appendChild(script); + } + }; + + const cleanUpGadgetText = () => { + const gadgetElement = document.querySelector(".goog-te-gadget"); + if (gadgetElement) { + const textNodes = gadgetElement.childNodes; + textNodes.forEach((node) => { + if (node.nodeType === Node.TEXT_NODE) { + node.textContent = ""; // Clear text content + } + }); + } + }; + loadGoogleTranslateScript(); + + if (window.google && window.google.translate) { + window.googleTranslateInit(); + } + + return () => { + // Cleanup logic if necessary + }; + }, []); + + return ( +
+ +
+ ); +}; + +export default GoogleTranslate; diff --git a/frontend/src/Pages/Herosection.jsx b/frontend/src/Pages/Herosection.jsx index d674302..750dcf4 100644 --- a/frontend/src/Pages/Herosection.jsx +++ b/frontend/src/Pages/Herosection.jsx @@ -17,6 +17,7 @@ import Navbar from "../components/navbar"; import Language from "../components/language"; import { FaUserAlt } from "react-icons/fa"; import Popup from "../components/popup"; +import GoogleTranslate from "./GoogleTranslate"; const Herosection = () => { const navigate = useNavigate(); @@ -63,12 +64,19 @@ const Herosection = () => {
+ - +
+ +
+

Namaste !! Yatree{" "}

From 5d92019f6e7647b1608e74eadb455cec6d4bf98b Mon Sep 17 00:00:00 2001 From: Ayush Date: Tue, 29 Oct 2024 20:23:13 +0530 Subject: [PATCH 2/2] added rate limit middleware --- backend/package-lock.json | 16 ++++++++++++++++ backend/package.json | 1 + backend/routes/authRoutes.js | 24 ++++++++++++++++-------- 3 files changed, 33 insertions(+), 8 deletions(-) diff --git a/backend/package-lock.json b/backend/package-lock.json index 54dbbc5..a8bc557 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -16,6 +16,7 @@ "depcheck": "^1.4.7", "dotenv": "^16.4.5", "express": "^4.21.1", + "express-rate-limit": "^7.4.1", "jsonwebtoken": "^9.0.2", "mongoose": "^8.7.0", "node": "^22.8.0", @@ -1150,6 +1151,21 @@ "node": ">= 0.10.0" } }, + "node_modules/express-rate-limit": { + "version": "7.4.1", + "resolved": "https://registry.npmjs.org/express-rate-limit/-/express-rate-limit-7.4.1.tgz", + "integrity": "sha512-KS3efpnpIDVIXopMc65EMbWbUht7qvTCdtCR2dD/IZmi9MIkopYESwyRqLgv8Pfu589+KqDqOdzJWW7AHoACeg==", + "license": "MIT", + "engines": { + "node": ">= 16" + }, + "funding": { + "url": "https://github.com/sponsors/express-rate-limit" + }, + "peerDependencies": { + "express": "4 || 5 || ^5.0.0-beta.1" + } + }, "node_modules/express/node_modules/cookie": { "version": "0.7.1", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.7.1.tgz", diff --git a/backend/package.json b/backend/package.json index 7004140..d201d0b 100644 --- a/backend/package.json +++ b/backend/package.json @@ -11,6 +11,7 @@ "depcheck": "^1.4.7", "dotenv": "^16.4.5", "express": "^4.21.1", + "express-rate-limit": "^7.4.1", "jsonwebtoken": "^9.0.2", "mongoose": "^8.7.0", "node": "^22.8.0", diff --git a/backend/routes/authRoutes.js b/backend/routes/authRoutes.js index d1f7bca..8f17bc1 100644 --- a/backend/routes/authRoutes.js +++ b/backend/routes/authRoutes.js @@ -1,4 +1,5 @@ import express from "express"; +import rateLimit from "express-rate-limit"; import { registerUser, loginUser, @@ -14,30 +15,37 @@ import { submitFeedback } from "../controllers/submitFeedback.js"; const router = express.Router(); +const loginLimiter = rateLimit({ + windowMs: 5 * 60 * 1000, // 55 minutes + max: 5, // Limit each IP to 5 requests per windowMs + message: "Too many login attempts from this IP, please try again later.", +}); + // Register route router.post("/register", registerUser); -// Login route -router.post("/login", loginUser); +// Login route with rate limiter +router.post("/login", loginLimiter, loginUser); // Logout route router.post("/logout", verifyJWT, logoutUser); // Verify route router.get("/verify", verifyUser); + +// Feedback route +router.post("/feedback", verifyJWT, submitFeedback); -router.post("/feedback" , verifyJWT, submitFeedback) - -//cloakroom bookings route +// Cloakroom bookings route router.post("/bookCloakroom", verifyJWT, createCloakroomBooking); -//wheelchair bookings route +// Wheelchair bookings route router.post("/bookWheelchair", verifyJWT, createWheelchairBooking); -//coolie bookings route +// Coolie bookings route router.post("/bookCoolie", verifyJWT, createCoolieBooking); -// get all stations route +// Get all stations route router.get("/all-stations", verifyJWT, sendStations); export default router;