diff --git a/package.json b/package.json index 33d7efb..39b940c 100644 --- a/package.json +++ b/package.json @@ -11,6 +11,7 @@ "aos": "^2.3.4", "axios": "^1.5.1", "framer-motion": "^11.1.9", + "jwt-decode": "^4.0.0", "react": "^18.2.0", "react-dom": "^18.2.0", "react-hot-toast": "^2.4.1", diff --git a/server/controllers/Auth.js b/server/controllers/Auth.js index cafbd5d..124011e 100644 --- a/server/controllers/Auth.js +++ b/server/controllers/Auth.js @@ -3,7 +3,7 @@ const User = require("../models/studentLoginInfo"); const jwt = require("jsonwebtoken"); const Canteen = require("../models/canteenLoginInfo"); const Session = require("../models/session"); -const Contact = require('../models/Contact'); +const Contact = require("../models/Contact"); const { forgotPasswordToken, verifyToken, @@ -76,7 +76,7 @@ exports.studentSignup = async (req, res) => { exports.studentLogin = async (req, res) => { try { - console.log(req.body); + const { email, password } = req.body; if (!email || !password) { @@ -87,13 +87,16 @@ exports.studentLogin = async (req, res) => { } let user = await User.findOne({ email }); + if (!user) { + console.log("User not found"); return res.status(401).json({ success: false, message: "User is not registred", }); } + console.log("This is our user", user); const payload = { email: user.email, id: user._id, @@ -115,7 +118,6 @@ exports.studentLogin = async (req, res) => { user = user.toObject(); user.token = token; user.password = undefined; - console.log(user); // const options = { // expires: new Date(Date.now() + 3 * 24 * 60 * 60 * 1000), @@ -142,7 +144,6 @@ exports.studentLogin = async (req, res) => { user, }); } else { - return res.status(403).json({ success: false, message: "Pasword Incorrect", @@ -265,7 +266,11 @@ exports.canteenSignup = async (req, res) => { // Create a token const token = jwt.sign( - { id: canteen._id, email: canteen.email }, + { + id: canteen._id, + email: canteen.email, + accountType: canteen.accountType, + }, process.env.JWT_SECRET, { expiresIn: "1h", // Set token expiration time as needed @@ -442,21 +447,20 @@ exports.changeCanteenPassword = async (req, res) => { }); }; - //contactUs exports.saveContactMessage = async (req, res) => { try { const { name, email, message } = req.body; if (!name || !email || !message) { - return res.status(400).send('All fields are required'); + return res.status(400).send("All fields are required"); } const newContact = new Contact({ name, email, message }); await newContact.save(); - res.status(201).send('Message received'); + res.status(201).send("Message received"); } catch (error) { - console.error('Error saving message:', error.message, error); - res.status(500).send('Error saving message'); + console.error("Error saving message:", error.message, error); + res.status(500).send("Error saving message"); } }; diff --git a/server/package.json b/server/package.json index 9875b1c..371e12c 100644 --- a/server/package.json +++ b/server/package.json @@ -21,6 +21,7 @@ "express-async-handler": "^1.2.0", "faker": "^5.5.3", "jsonwebtoken": "^9.0.2", + "mongodb": "^6.7.0", "mongoose": "^7.6.13", "multer": "^1.4.5-lts.1", "nodemailer": "^6.9.13", diff --git a/server/server.js b/server/server.js index 6836f6c..ea5825c 100644 --- a/server/server.js +++ b/server/server.js @@ -27,8 +27,8 @@ app.use("/api/v1", studentRoutes); app.use("/api/v1", uploadFileRouter); app.use('/api/contact', contactRoutes); -app.listen(PORT, () => { - console.log(`Server started succesfully at ${PORT}`); +app.listen(process.env.PORT, () => { + console.log(`Server started succesfully at ${process.env.PORT}`); }); //getting connected to databse diff --git a/src/authContext.js b/src/authContext.js index 4b1fb0b..bdb1d70 100644 --- a/src/authContext.js +++ b/src/authContext.js @@ -1,4 +1,4 @@ -import { createContext, useContext, useState } from "react"; +import { createContext, useContext, useState, useEffect } from "react"; const authContext = createContext({ isAuthenticated: false @@ -8,13 +8,34 @@ export const useAuth = () => useContext(authContext); const AuthProvider = ({ children }) => { const [isAuthenticated, setAuthenticated] = useState(false); + + useEffect(() => { + const token = localStorage.getItem('authToken'); + if (token) { + setAuthenticated(true); + } + }, []); - const checkAuthentication = (token) => { - setAuthenticated(!!token); + const login = (token) => { + // saving the token to local storage when canteen user logIn + localStorage.setItem('authToken', token); + setAuthenticated(true); + }; + + const signUp = (token) => { + // saving the token to local storage when canteen user logIn + localStorage.setItem('authToken', token); + setAuthenticated(true); + }; + + const logout = () => { + + localStorage.removeItem('authToken'); + setAuthenticated(false); }; return ( - + {children} ); diff --git a/src/components/CanteenCard.jsx b/src/components/CanteenCard.jsx index af60d08..776ce00 100644 --- a/src/components/CanteenCard.jsx +++ b/src/components/CanteenCard.jsx @@ -31,7 +31,7 @@ const CanteenCard = ({ canteen }) => { }; return ( -
+
{loading ? (
diff --git a/src/components/FoodCard.jsx b/src/components/FoodCard.jsx new file mode 100644 index 0000000..0b88738 --- /dev/null +++ b/src/components/FoodCard.jsx @@ -0,0 +1,20 @@ +// components/FoodCard.js +import React from 'react'; + +function FoodCard({ dish, onClick }) { + const placeholderImage = "https://www.holidify.com/blog/wp-content/uploads/2015/11/Maharashtras_Misal_Pav.jpg"; + const defaultDescription = "No description available."; + // https://via.placeholder.com/150 + return ( +
+ {dish.dish +
+

{dish.dish}

+

{dish.description || defaultDescription}

+ {/*

${dish.price}

*/} +
+
+ ); +} + +export default FoodCard; diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index ed31645..0c1170a 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -45,65 +45,6 @@ const Navbar = () => {
-<<<<<<< Updated upstream - -
- }>Home - }>About - }>News - }>RateUs -
- -
-
- -
- - - -
-
-
- - -
- - - - {isOpen && ( - -
- Home - About us - News - Contact - -=======
->>>>>>> Stashed changes {isOpen && ( @@ -152,11 +92,7 @@ const Navbar = () => { About us News Contact -<<<<<<< Updated upstream - RateUs -======= RateUs ->>>>>>> Stashed changes {/* Conditionally render "My Canteen" button */} {canteenId && ( My Canteen @@ -174,29 +110,6 @@ const Navbar = () => { -<<<<<<< Updated upstream - Rateus - - - - - - - -
- )} -
- - - -======= ->>>>>>> Stashed changes ); }; @@ -229,10 +142,6 @@ const IconHome = () => 🏠; const IconAbout = () => ℹī¸; const IconNews = () => 📰; const IconRateUs = () => ⭐; -<<<<<<< Updated upstream -const IconCanteen = () => đŸĨ— -======= const IconCanteen = () => đŸĨ—; ->>>>>>> Stashed changes export default Navbar; diff --git a/src/pages/About.jsx b/src/pages/About.jsx index 95352f4..d7d3478 100644 --- a/src/pages/About.jsx +++ b/src/pages/About.jsx @@ -11,7 +11,7 @@ import { useNavigate } from "react-router-dom"; const About = () => { const navigate = useNavigate() - const { isAuthenticated } = useAuth(); + const { isAuthenticated } = localStorage.getItem('token'); const [loading,setLoading] = useState(false); useEffect(() => { @@ -20,11 +20,11 @@ const About = () => { setLoading(false); }, []); - useEffect(() => { - if(!isAuthenticated){ - navigate('/') - } - }, []) +// useEffect(() => { +// if(!isAuthenticated){ +// navigate('/') +// } +// }, []) return ( <> diff --git a/src/pages/AddFoodItem.jsx b/src/pages/AddFoodItem.jsx index a897bd2..f7460cc 100644 --- a/src/pages/AddFoodItem.jsx +++ b/src/pages/AddFoodItem.jsx @@ -83,7 +83,7 @@ function AddFoodItem() { }; return ( -
+
{ const formRef = useRef(); @@ -84,84 +84,79 @@ const Contact = () => { }; return ( -
-

Get in touch

-

Contact Us.

-
- -
-
-
-
- - -
- - - - -
- -=======
{breakfast && (
@@ -373,7 +254,6 @@ function MenuPage() { Submit Feedback
->>>>>>> Stashed changes ) } diff --git a/src/pages/Rateus.jsx b/src/pages/Rateus.jsx index bbc4eb7..14ac6d8 100644 --- a/src/pages/Rateus.jsx +++ b/src/pages/Rateus.jsx @@ -1,4 +1,6 @@ import React, { useState } from 'react'; +import { ToastContainer, toast } from 'react-toastify'; +import 'react-toastify/dist/ReactToastify.css'; import Footer from "../components/Footer"; import Navbar from "../components/Navbar"; @@ -16,10 +18,9 @@ const RateUs = () => { const handleSubmit = () => { if (rating && feedback.trim() !== '') { - console.log('Rating:', rating); - console.log('Feedback:', feedback); + toast.success('Thank you for your feedback :)'); } else { - console.log("Please Fill All The Details :("); + toast.error('Please fill all the details :('); } }; @@ -67,6 +68,17 @@ const RateUs = () => {
+
); }; diff --git a/src/pages/SectionPage.jsx b/src/pages/SectionPage.jsx index 97bd0bc..04d6708 100644 --- a/src/pages/SectionPage.jsx +++ b/src/pages/SectionPage.jsx @@ -66,7 +66,7 @@ const SectionPage = () => { return (
-
+
{loading ? ( ) : ( diff --git a/src/pages/Signup.jsx b/src/pages/Signup.jsx index 1c26e01..c2ace93 100644 --- a/src/pages/Signup.jsx +++ b/src/pages/Signup.jsx @@ -59,24 +59,11 @@ function Signup() { async function submitHandler(event) { event.preventDefault(); console.log("ENV FILE", process.env.REACT_APP_BASE_URL); -<<<<<<< Updated upstream - -======= ->>>>>>> Stashed changes if (lowerValidated && upperValidated && numberValidated && specialValidated && lengthValidated) { const apiUrl = formData.accountType === "User" ? `${process.env.REACT_APP_BASE_URL}/studentSignup` : `${process.env.REACT_APP_BASE_URL}/canteenSignup`; -<<<<<<< Updated upstream - - try { - setLoading(true); - - const response = await axios.post(apiUrl, formData); - - toast.success("Account Created Successfully!"); -======= try { setLoading(true); @@ -85,23 +72,13 @@ function Signup() { toast.success("Account Created Successfully!"); ->>>>>>> Stashed changes if (formData.accountType === "User") { navigate("/"); } else { const token = response.data.token; localStorage.setItem("token", token); localStorage.setItem("canteenId", response.data.cantId); -<<<<<<< Updated upstream - navigate("/home"); - } else { - navigate("/"); - - navigate(`/section/${response.data.cantId}`); - -======= navigate(`/section/${response.data.cantId}`); ->>>>>>> Stashed changes } } catch (error) { const errorMessage = error.response?.data?.message || "Failed to create account. Please try again.";