From dcd34f9adca35be895b685b2c97e5fe94c66faa7 Mon Sep 17 00:00:00 2001 From: Deeksha Varshney Date: Fri, 25 Oct 2024 00:07:22 +0530 Subject: [PATCH 1/2] successfully change --- SignUp/signup.js | 52 ++++--------------- backend/app.js | 4 +- backend/package-lock.json | 26 ++++++++++ backend/package.json | 3 +- login/auth.js | 104 +++++++++++++++++--------------------- login/login.html | 50 +++++++----------- 6 files changed, 105 insertions(+), 134 deletions(-) diff --git a/SignUp/signup.js b/SignUp/signup.js index bd139f02..cb655e77 100644 --- a/SignUp/signup.js +++ b/SignUp/signup.js @@ -1,59 +1,24 @@ document.addEventListener("DOMContentLoaded", () => { const signupButton = document.querySelector(".signup-button"); - // List of trusted email domains - const trustedDomains = ["gmail.com", "outlook.com", "yahoo.com", "hotmail.com" , "protonmail.com" , "icloud.com" , "tutanota.com"]; - signupButton.addEventListener("click", (e) => { e.preventDefault(); - const name = document.querySelector("#username").value; const email = document.querySelector("#email").value; const password = document.querySelector("#password").value; const confirmPassword = document.querySelector("#confirm-password").value; - const emailError = document.querySelector("#email-error"); // Reference to email error div - const passwordError = document.querySelector("#password-error"); // Reference to password error div - - // Clear any previous error messages - emailError.textContent = ""; - emailError.style.display = "none"; // Hide the error message by default - passwordError.textContent = ""; - passwordError.style.display = "none"; // Hide the error message by default if (!name || !email || !password || !confirmPassword) { - emailError.textContent = "Every field is required."; - emailError.style.display = "block"; + alert("Every field is required."); return; } - // Email domain validation - const emailDomain = email.split("@")[1]; // Get the domain from the email - if (!trustedDomains.includes(emailDomain)) { - emailError.textContent = "Please use an email address from a trusted provider (e.g., Gmail, Outlook, Yahoo) etc."; - emailError.style.display = "block"; - return; - } - - // Password matching validation if (password !== confirmPassword) { - passwordError.textContent = "Passwords do not match."; - passwordError.style.display = "block"; + alert("Passwords do not match."); return; } - - const emailPattern = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/; - if (!emailPattern.test(email)) { - alert("Please enter a valid email address."); - return; // Stop the function if the email is not in the right format - } - - const userdata = { - name, - email, - password, - confirmPassword - }; + const userdata = { name, email, password }; registerUser(userdata); }); @@ -64,12 +29,15 @@ document.addEventListener("DOMContentLoaded", () => { headers: { "content-type": "application/json" }, body: JSON.stringify(user) }); - const data = await res.json(); - console.log(data); - window.location.href = "http://127.0.0.1:5500/Collect-your-GamingTools/login/login.html"; + if (data.success) { + alert('Signup successful! Redirecting to login...'); + window.location.href = "../login/login.html"; // Redirect after signup + } else { + alert(data.message); // Show error message + } } catch (err) { - console.log(err.message); + alert('Error: ' + err.message); // Show error message } }; diff --git a/backend/app.js b/backend/app.js index 84d8ceb0..b7779273 100644 --- a/backend/app.js +++ b/backend/app.js @@ -12,7 +12,9 @@ databaseconnect(); app.use(express.json()); // Built-in middleware app.use(cookieParser()); // Third-party middleware -app.use(cors({ origin: [process.env.CLIENT_URL], credentials: true })); //Third-party middleware +// app.use(cors({ origin: [process.env.CLIENT_URL], credentials: true })); //Third-party middleware +app.use(cors({ origin: "https://collect-your-gamingtools.netlify.app", credentials: true })); + // Auth router app.use('/auth', authRouter); diff --git a/backend/package-lock.json b/backend/package-lock.json index 8be6ff87..823a2a10 100644 --- a/backend/package-lock.json +++ b/backend/package-lock.json @@ -16,8 +16,10 @@ "dotenv": "^16.4.5", "email-validator": "^2.0.4", "express": "^4.21.0", + "express-rate-limit": "^7.4.1", "jsonwebtoken": "^9.0.2", "mongoose": "^8.7.0", + "nodemailer": "^6.9.15", "nodemon": "^3.1.5" } }, @@ -547,6 +549,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.6.0", "resolved": "https://registry.npmjs.org/cookie/-/cookie-0.6.0.tgz", @@ -1315,6 +1332,15 @@ "webidl-conversions": "^3.0.0" } }, + "node_modules/nodemailer": { + "version": "6.9.15", + "resolved": "https://registry.npmjs.org/nodemailer/-/nodemailer-6.9.15.tgz", + "integrity": "sha512-AHf04ySLC6CIfuRtRiEYtGEXgRfa6INgWGluDhnxTZhHSKvrBu7lc1VVchQ0d8nPc4cFaZoPq8vkyNoZr0TpGQ==", + "license": "MIT-0", + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/nodemon": { "version": "3.1.5", "resolved": "https://registry.npmjs.org/nodemon/-/nodemon-3.1.5.tgz", diff --git a/backend/package.json b/backend/package.json index 2d1344de..39bbb33c 100644 --- a/backend/package.json +++ b/backend/package.json @@ -17,10 +17,11 @@ "crypto": "^1.0.1", "dotenv": "^16.4.5", "email-validator": "^2.0.4", - "nodemailer": "^6.9.15", "express": "^4.21.0", + "express-rate-limit": "^7.4.1", "jsonwebtoken": "^9.0.2", "mongoose": "^8.7.0", + "nodemailer": "^6.9.15", "nodemon": "^3.1.5" } } diff --git a/login/auth.js b/login/auth.js index c6f5887e..d51f9fa3 100644 --- a/login/auth.js +++ b/login/auth.js @@ -1,68 +1,56 @@ - - import { initializeApp } from "https://www.gstatic.com/firebasejs/10.14.1/firebase-app.js"; - import { getAuth, signOut, onAuthStateChanged, GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/10.14.1/firebase-auth.js"; - - // Firebase configuration - const firebaseConfig = { - apiKey: process.env.FIREBASE_API_KEY, - authDomain: process.env.FIREBASE_AUTH_DOMAIN, - projectId: process.env.FIREBASE_PROJECT_ID, - storageBucket: process.env.FIREBASE_STORAGE_BUCKET, - messagingSenderId: process.env.FIREBASE_MESSAGING_SENDER_ID, - appId: process.env.FIREBASE_APP_ID, +import { initializeApp } from "https://www.gstatic.com/firebasejs/10.14.1/firebase-app.js"; +import { getAuth, signOut, onAuthStateChanged, GoogleAuthProvider, signInWithPopup } from "https://www.gstatic.com/firebasejs/10.14.1/firebase-auth.js"; + +// Firebase configuration +const firebaseConfig = { + apiKey: "YOUR_API_KEY", + authDomain: "YOUR_AUTH_DOMAIN", + projectId: "YOUR_PROJECT_ID", + storageBucket: "YOUR_STORAGE_BUCKET", + messagingSenderId: "YOUR_MESSAGING_SENDER_ID", + appId: "YOUR_APP_ID" }; +// Initialize Firebase +const app = initializeApp(firebaseConfig); +const auth = getAuth(app); +const provider = new GoogleAuthProvider(); - - // Initialize Firebase - const app = initializeApp(firebaseConfig); - const auth = getAuth(app); - auth.languageCode = "en"; - const provider = new GoogleAuthProvider(); - - // Sign in with Google - const googleLoginBtn = document.getElementById('google-login-btn'); - googleLoginBtn?.addEventListener('click', function () { +// Sign in with Google +document.getElementById('google-login-btn').addEventListener('click', function () { signInWithPopup(auth, provider) - .then((result) => { - const user = result.user; - console.log('User logged in:', user); - - // Redirect to the home page - window.location.href = "../index.html"; - }) - .catch((error) => { - console.error('Login error:', error); - }); - }); - - // Handle auth state change and toggle login/logout button - window.addEventListener('load', () => { + .then((result) => { + const user = result.user; + alert(`Welcome ${user.displayName}!`); + window.location.href = "../index.html"; + }) + .catch((error) => { + alert('Login failed: ' + error.message); + }); +}); + +// Handle auth state change +onAuthStateChanged(auth, (user) => { const authLink = document.getElementById('auth-link'); - - onAuthStateChanged(auth, (user) => { - if (user) { - // If the user is logged in, change the link to "Logout" + if (user) { authLink.textContent = 'Logout'; - authLink.removeAttribute('href'); - authLink.addEventListener('click', handleLogout); - } else { - // If the user is not logged in, change the link to "Login" + authLink.onclick = handleLogout; + } else { authLink.textContent = 'Login'; authLink.setAttribute('href', 'login/login.html'); - authLink.removeEventListener('click', handleLogout); - } - }); - }); + } +}); - // Handle logout - function handleLogout() { +// Handle logout +function handleLogout() { signOut(auth) - .then(() => { - console.log('User logged out'); - window.location.reload(); // Reload the page if needed - }) - .catch((error) => { - console.error('Logout error:', error); - }); - } + .then(() => { + alert('Logged out successfully!'); + window.location.reload(); + }) + .catch((error) => { + alert('Logout failed: ' + error.message); + }); +} + + diff --git a/login/login.html b/login/login.html index e985fdf6..de110417 100644 --- a/login/login.html +++ b/login/login.html @@ -6,24 +6,18 @@ Collect Your Gaming Tools - Login - - -
- - - Back - -
+ ← Back +
+ - - \ No newline at end of file + Date: Fri, 25 Oct 2024 00:18:09 +0530 Subject: [PATCH 2/2] successfully change --- SignUp/signup.html | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/SignUp/signup.html b/SignUp/signup.html index 723c3b67..8c99dd96 100644 --- a/SignUp/signup.html +++ b/SignUp/signup.html @@ -8,11 +8,11 @@