Skip to content

Commit

Permalink
Merge branch 'main' into PublicReview
Browse files Browse the repository at this point in the history
  • Loading branch information
Taranpreet10451 authored Jun 24, 2024
2 parents 59ed033 + d96dcec commit 7fd4145
Show file tree
Hide file tree
Showing 18 changed files with 187 additions and 353 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 14 additions & 10 deletions server/controllers/Auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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) {
Expand All @@ -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,
Expand All @@ -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),
Expand All @@ -142,7 +144,6 @@ exports.studentLogin = async (req, res) => {
user,
});
} else {

return res.status(403).json({
success: false,
message: "Pasword Incorrect",
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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");
}
};

Expand Down
1 change: 1 addition & 0 deletions server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 25 additions & 4 deletions src/authContext.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { createContext, useContext, useState } from "react";
import { createContext, useContext, useState, useEffect } from "react";

const authContext = createContext({
isAuthenticated: false
Expand All @@ -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 (
<authContext.Provider value={{ isAuthenticated, checkAuthentication }}>
<authContext.Provider value={{ isAuthenticated, login, logout, signUp }}>
{children}
</authContext.Provider>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/CanteenCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ const CanteenCard = ({ canteen }) => {
};

return (
<div className="max-w-(18rem) bg-white border border-white rounded-lg shadow dark:bg-white dark:border-white my-4 mx-2 transition duration-300 ease-in-out transform hover:scale-105 hover:shadow-lg hover:shadow-green-500/50 ...">
<div className="max-w-(18rem) bg-white border border-white rounded-lg shadow dark:bg-none dark:border-white my-4 mx-2 transition duration-300 ease-in-out transform hover:scale-105 hover:shadow-lg hover:shadow-green-500/50 ...">
{loading ? (
<div className="flex justify-center items-center h-48 w-full">
<ClipLoader size={50} color={"#123abc"} loading={loading} />
Expand Down
20 changes: 20 additions & 0 deletions src/components/FoodCard.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<div className="bg-white shadow-md rounded-lg overflow-hidden border-2 border-gray-300 cursor-pointer transition-transform duration-300 ease-in-out transform hover:-translate-y-1" onClick={onClick}>
<img src={dish.imageUrl || placeholderImage} alt={dish.dish || "No image available"} className="w-full h-48 object-cover"/>
<div className="p-4">
<h3 className="text-lg text-black font-bold mb-2">{dish.dish}</h3>
<p className="text-gray-700">{dish.description || defaultDescription}</p>
{/* <p className="text-gray-700 font-bold">${dish.price}</p> */}
</div>
</div>
);
}

export default FoodCard;
91 changes: 0 additions & 91 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,65 +45,6 @@ const Navbar = () => {
</div>
</div>

<<<<<<< Updated upstream

<div className="ml-16 flex gap-6 items-baseline space-x-4 ">
<NavItem to="/home" className="nav-item" icon={<IconHome />}>Home</NavItem>
<NavItem to="/about" className="nav-item" icon={<IconAbout />}>About</NavItem>
<NavItem to="/news" className="nav-item" icon={<IconNews />}>News</NavItem>
<NavItem to="/rateus" className="nav-item" icon={<IconRateUs />}>RateUs</NavItem>
</div>

</div>
<div className="hidden md:flex items-center gap-5">
<button onClick={toggleTheme} className="p-2 rounded focus:outline-none text-4xl border-none outline-none ">
{theme === 'dark' ? '🌞' : '🌙'}
</button>
<div>
<Link to="/">
<button

className={`py-1 px-2 rounded w-full h-auto text-l relative z-0 rounded-lg transition-all duration-200 hover:scale-110 ${theme === 'dark' ? 'bg-white text-black' : 'bg-green-400 hover:bg-green-600 hover:shadow-green text-white'}`}

>
Log out
</button>
</Link>
</div>
</div>
<div className="-mr-2 flex md:hidden">
<button onClick={toggleTheme} className="p-2 rounded focus:outline-none text-2xl border-none outline-none ">
{theme === 'dark' ? '🌞' : '🌙'}
</button>
<button
onClick={toggleMenu}
className="inline-flex items-center p-2 rounded-md text-gray-400 hover:text-white hover:bg-gray-700 focus:outline-none focus:bg-gray-700 focus:text-white"
aria-expanded="false"
>
{isOpen ? (
<IoClose className="text-white" />
) : (
<GiHamburgerMenu className="text-white" />
)}
</button>
</div>
</div>
</div>
<AnimatePresence>
{isOpen && (
<motion.div
initial={{ opacity: 0, y: -50 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -50 }}
className="md:hidden absolute left-0 w-full flex flex-col items-center justify-center"
>
<div className="w-[100%] bg-[#152146] px-[20%] pt-2 pb-3 space-y-1 mt-1 dark:bg-teal-900">
<MobileNavItem to="/home">Home</MobileNavItem>
<MobileNavItem to="/about">About us</MobileNavItem>
<MobileNavItem to="/news">News</MobileNavItem>
<MobileNavItem to="/contact">Contact</MobileNavItem>

=======
<div className="hidden md:flex items-center gap-5">
<button onClick={toggleTheme} className="p-2 rounded focus:outline-none text-4xl border-none outline-none">
{theme === 'dark' ? '🌞' : '🌙'}
Expand Down Expand Up @@ -137,7 +78,6 @@ const Navbar = () => {
</div>
</div>
</div>
>>>>>>> Stashed changes

<AnimatePresence>
{isOpen && (
Expand All @@ -152,11 +92,7 @@ const Navbar = () => {
<MobileNavItem to="/about">About us</MobileNavItem>
<MobileNavItem to="/news">News</MobileNavItem>
<MobileNavItem to="/contact">Contact</MobileNavItem>
<<<<<<< Updated upstream
<MobileNavItem to="/rateus">RateUs</MobileNavItem>
=======
<MobileNavItem to="/rateus">RateUs</MobileNavItem>
>>>>>>> Stashed changes
{/* Conditionally render "My Canteen" button */}
{canteenId && (
<MobileNavItem to={`/section/${canteenId}`}>My Canteen</MobileNavItem>
Expand All @@ -174,29 +110,6 @@ const Navbar = () => {
</AnimatePresence>
</nav>
</>
<<<<<<< Updated upstream
<MobileNavItem to="/rateus">Rateus</MobileNavItem>

<MobileNavItem to="/">
<Link to="/">
<button

className={`rounded transition duration-300 ease-in-out transform hover:scale-105 ${theme === 'dark' ? 'bg-white text-black' : 'bg-green-500 hover:bg-green-700 text-white py-1 px-2'}`}

>
Log out
</button>
</Link>
</MobileNavItem>
</div>
</motion.div>
)}
</AnimatePresence>
</div>
</nav>
</>
=======
>>>>>>> Stashed changes
);
};

Expand Down Expand Up @@ -229,10 +142,6 @@ const IconHome = () => <span>🏠</span>;
const IconAbout = () => <span>ℹ️</span>;
const IconNews = () => <span>📰</span>;
const IconRateUs = () => <span></span>;
<<<<<<< Updated upstream
const IconCanteen = () => <span>🥗</span>
=======
const IconCanteen = () => <span>🥗</span>;
>>>>>>> Stashed changes

export default Navbar;
12 changes: 6 additions & 6 deletions src/pages/About.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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(() => {
Expand All @@ -20,11 +20,11 @@ const About = () => {
setLoading(false);
}, []);

useEffect(() => {
if(!isAuthenticated){
navigate('/')
}
}, [])
// useEffect(() => {
// if(!isAuthenticated){
// navigate('/')
// }
// }, [])

return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/pages/AddFoodItem.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function AddFoodItem() {
};

return (
<div className="flex justify-center items-center h-[80vh] bg-white">
<div className="flex justify-center items-center h-[80vh] ">
<form
onSubmit={handleSubmit}
className="bg-white p-6 rounded shadow-lg w-full max-w-sm border-2"
Expand Down
Loading

0 comments on commit 7fd4145

Please sign in to comment.