From 649dad75cb90cc360fd2dec41ca2a2971019038c Mon Sep 17 00:00:00 2001 From: Mann Patel <130435633+MannPatel0@users.noreply.github.com> Date: Fri, 18 Apr 2025 19:05:20 -0600 Subject: [PATCH] update to the color --- backend/controllers/user.js | 61 +++++++- backend/routes/user.js | 4 + frontend/src/App.jsx | 36 +++-- frontend/src/components/ProductForm.jsx | 102 ++++++++----- frontend/src/pages/Favorites.jsx | 10 +- frontend/src/pages/Home.jsx | 22 ++- frontend/src/pages/ProductDetail.jsx | 40 ++--- frontend/src/pages/Settings.jsx | 137 +++--------------- .../__pycache__/app.cpython-313.pyc | Bin 5724 -> 5724 bytes 9 files changed, 213 insertions(+), 199 deletions(-) diff --git a/backend/controllers/user.js b/backend/controllers/user.js index 27a0dc3..32aef17 100644 --- a/backend/controllers/user.js +++ b/backend/controllers/user.js @@ -134,6 +134,62 @@ exports.completeSignUp = async (req, res) => { } }; +exports.doLogin = async (req, res) => { + const { email, password } = req.body; + + // Input validation + if (!email || !password) { + return res.status(400).json({ + found: false, + error: "Email and password are required", + }); + } + + try { + // Query to find user with matching email + const query = "SELECT * FROM User WHERE email = ?"; + const [data, fields] = await db.execute(query, [email]); + + // Check if user was found + if (data && data.length > 0) { + const user = data[0]; + + // Verify password match + if (user.Password === password) { + // Consider using bcrypt for secure password comparison + // Return user data without password + return res.json({ + found: true, + userID: user.UserID, + name: user.Name, + email: user.Email, + UCID: user.UCID, + phone: user.Phone, + address: user.Address, + }); + } else { + // Password doesn't match + return res.json({ + found: false, + error: "Invalid email or password", + }); + } + } else { + // User not found + return res.json({ + found: false, + error: "Invalid email or password", + }); + } + } catch (error) { + console.error("Error logging in:", error); + return res.status(500).json({ + found: false, + error: "Database error occurred", + }); + } +}; + exports.getAllUser = async (req, res) => { try { const [users, fields] = await db.execute("SELECT * FROM User;"); @@ -174,6 +230,7 @@ exports.findUserByEmail = async (req, res) => { UCID: user.UCID, phone: user.Phone, address: user.Address, + password: user.Password, // Include any other fields your user might have // Make sure the field names match exactly with your database column names }); @@ -201,7 +258,7 @@ exports.updateUser = async (req, res) => { const phone = req.body?.phone; const UCID = req.body?.UCID; const address = req.body?.address; - + const password = req.body?.password; if (!userId) { return res.status(400).json({ error: "User ID is required" }); } @@ -213,7 +270,7 @@ exports.updateUser = async (req, res) => { if (phone) updateData.phone = phone; if (UCID) updateData.UCID = UCID; if (address) updateData.address = address; - + if (password) updateData.password = password; if (Object.keys(updateData).length === 0) { return res.status(400).json({ error: "No valid fields to update" }); } diff --git a/backend/routes/user.js b/backend/routes/user.js index 3d11102..1ccbc88 100644 --- a/backend/routes/user.js +++ b/backend/routes/user.js @@ -7,6 +7,7 @@ const { findUserByEmail, updateUser, deleteUser, + doLogin, } = require("../controllers/user"); const router = express.Router(); @@ -26,6 +27,9 @@ router.get("/fetch_all_users", getAllUser); //Fetch One user Data with all fields: router.post("/find_user", findUserByEmail); +//Fetch One user Data with all fields: +router.post("/do_login", doLogin); + //Update A uses Data: router.post("/update", updateUser); diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index c266822..4b88b70 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -52,10 +52,9 @@ function App() { return () => window.removeEventListener("resize", handleResize); }, []); - -useEffect(() => { - sendSessionDataToServer(); -}, []); + useEffect(() => { + sendSessionDataToServer(); + }, []); // Send verification code const sendVerificationCode = async (userData) => { @@ -250,7 +249,7 @@ useEffect(() => { UCID: formValues.ucid, phone: formValues.phone, password: formValues.password, // This will be needed for the final signup - address: "NOT_GIVEN", + address: formValues.address, // Add this line client: 1, admin: 0, }; @@ -266,7 +265,7 @@ useEffect(() => { // Make API call to localhost:3030/find_user const response = await fetch( - "http://localhost:3030/api/user/find_user", + "http://localhost:3030/api/user/do_login", { method: "POST", headers: { @@ -301,7 +300,7 @@ useEffect(() => { // Save to localStorage to persist across refreshes sessionStorage.setItem("isAuthenticated", "true"); sessionStorage.setItem("user", JSON.stringify(userObj)); - sendSessionDataToServer(); // Call it after signup + sessionStorage.getItem("user"); console.log("Login successful for:", userData.email); @@ -370,8 +369,8 @@ useEffect(() => { try { // Retrieve data from sessionStorage const user = JSON.parse(sessionStorage.getItem("user")); - const isAuthenticated = - sessionStorage.getItem("isAuthenticated") === "true"; + // const isAuthenticated = + // sessionStorage.getItem("isAuthenticated") === "true"; if (!user || !isAuthenticated) { console.log("User is not authenticated"); @@ -532,6 +531,25 @@ useEffect(() => { )} + {isSignUp && ( +
+ + +
+ )} +
+ {/* Sold Status */} +
+
+ + + {editingProduct.isSold && ( + + Sold + + )} +
+
+ {/* Categories */}
- {/* Description */}
@@ -223,7 +231,7 @@ const ProductForm = ({ htmlFor="image-upload" className="block w-full p-3 border border-gray-300 bg-gray-50 text-center cursor-pointer hover:bg-gray-100" > - + Click to upload images @@ -280,19 +288,33 @@ const ProductForm = ({ {/* Actions */} -
+
- + +
+ + +
); diff --git a/frontend/src/pages/Favorites.jsx b/frontend/src/pages/Favorites.jsx index 0a30101..f36dc41 100644 --- a/frontend/src/pages/Favorites.jsx +++ b/frontend/src/pages/Favorites.jsx @@ -129,7 +129,7 @@ const Favorites = () => { {sortedFavorites.map((product) => (
@@ -150,10 +150,14 @@ const Favorites = () => { {product.name}
diff --git a/frontend/src/pages/Home.jsx b/frontend/src/pages/Home.jsx index 08b17a2..22dc205 100644 --- a/frontend/src/pages/Home.jsx +++ b/frontend/src/pages/Home.jsx @@ -1,6 +1,12 @@ import { useState, useEffect } from "react"; import { Link, useNavigate } from "react-router-dom"; -import { Tag, ChevronLeft, ChevronRight } from "lucide-react"; +import { + Tag, + ChevronLeft, + ChevronRight, + Bookmark, + BookmarkCheck, +} from "lucide-react"; import FloatingAlert from "../components/FloatingAlert"; // adjust path if needed @@ -246,7 +252,7 @@ const Home = () => { {/* Scrollable Listings Container */}
{recommended.map((recommended) => ( { e.preventDefault(); toggleFavorite(recommended.id); }} - className="absolute top-2 right-2 p-2 bg-white rounded-full shadow-sm hover:bg-gray-100 transition" + className="absolute top-0 right-0 p-2 rounded-bl-md bg-emerald-600 hover:bg-emerald-500 transition shadow-sm" > - + +
@@ -362,9 +368,9 @@ const Home = () => { e.preventDefault(); toggleFavorite(listing.id); }} - className="absolute top-2 right-2 p-2 bg-white rounded-full shadow-sm hover:bg-gray-100 transition" + className="absolute top-0 right-0 p-2 rounded-bl-md bg-emerald-600 hover:bg-emerald-500 transition shadow-sm" > - + +
@@ -454,9 +460,9 @@ const Home = () => { e.preventDefault(); toggleFavorite(history.id); }} - className="absolute top-2 right-2 p-2 bg-white rounded-full shadow-sm hover:bg-gray-100 transition" + className="absolute top-0 right-0 p-2 rounded-bl-md bg-emerald-600 hover:bg-emerald-500 transition shadow-sm" > - + + diff --git a/frontend/src/pages/ProductDetail.jsx b/frontend/src/pages/ProductDetail.jsx index 8de5e21..a5f0d73 100644 --- a/frontend/src/pages/ProductDetail.jsx +++ b/frontend/src/pages/ProductDetail.jsx @@ -9,6 +9,7 @@ import { Star, Phone, Mail, + Bookmark, } from "lucide-react"; import FloatingAlert from "../components/FloatingAlert"; // adjust path if needed @@ -247,7 +248,7 @@ const ProductDetail = () => { if (loading.product) { return (
-
+
); } @@ -261,7 +262,7 @@ const ProductDetail = () => {

{error.product}

Back to Listings @@ -278,7 +279,7 @@ const ProductDetail = () => {

Product Not Found

Back to Listings @@ -293,7 +294,7 @@ const ProductDetail = () => {
Back @@ -350,7 +351,7 @@ const ProductDetail = () => { {product.images.map((image, index) => (
selectImage(index)} > { {product.Name || "Unnamed Product"}
-
+
$ {typeof product.Price === "number" ? product.Price.toFixed(2) @@ -416,7 +418,7 @@ const ProductDetail = () => {
@@ -428,7 +430,7 @@ const ProductDetail = () => { href={`tel:${product.SellerPhone}`} className="flex items-center gap-2 p-3 hover:bg-gray-50 border-b border-gray-100" > - + Call Seller )} @@ -438,7 +440,7 @@ const ProductDetail = () => { href={`mailto:${product.SellerEmail}`} className="flex items-center gap-2 p-3 hover:bg-gray-50" > - + Email Seller )} @@ -475,7 +477,7 @@ const ProductDetail = () => {
{loading.reviews ? (
-
+
) : error.reviews ? (
@@ -522,7 +524,7 @@ const ProductDetail = () => {
@@ -580,7 +582,7 @@ const ProductDetail = () => { id="comment" value={reviewForm.comment} onChange={handleReviewInputChange} - className="w-full p-3 border border-gray-300 focus:outline-none focus:border-emerald-500" + className="w-full p-3 border border-gray-300 focus:outline-none focus:border-green-500" rows="4" required > @@ -596,7 +598,7 @@ const ProductDetail = () => {
+
+ + +
- {/* Security Section */} -
-
-
- -

Password

-
-
- -
-
-
-
- - -
- -
- - -
- -
- - -
-
- - -
-
-
- {/* Privacy Section */} {showAlert && ( setShowAlert(false)} /> )} @@ -448,7 +349,7 @@ const Settings = () => {
-
+
diff --git a/recommondation-engine/__pycache__/app.cpython-313.pyc b/recommondation-engine/__pycache__/app.cpython-313.pyc index a6e4997526bc1b3af7668c626850aae5e225d58a..f5efd97bfd14a014c6683a8edf8f01535a1d88e2 100644 GIT binary patch delta 21 bcmcbkb4Q2gGcPX}0}w>4V9eOa6CefvNB9N6 delta 21 bcmcbkb4Q2gGcPX}0}$-E`8RzdPk