diff --git a/README.md b/README.md index b15fecf..59f11d7 100644 --- a/README.md +++ b/README.md @@ -260,6 +260,7 @@ We extend our heartfelt gratitude to all the amazing contributors who have made + haseebzaki-07
@@ -274,14 +275,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
+ alo7lika
alolika bhowmik
- - Ashwinib26 @@ -296,6 +296,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made Tejas Benibagde + + itznayan @@ -310,22 +312,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made Tyarla Shirisha - - - meghanakn22 -
- meghanakn22 -
- - - - VinayLodhi1712 -
- Vinay Anand Lodhi -
- - - Amnyadav @@ -341,17 +327,10 @@ We extend our heartfelt gratitude to all the amazing contributors who have made - - Suhas-Koheda -
- Suhas Koheda -
- - - - Sumanbhadra + + haseebzaki-07
- Suman Bhadra + Haseeb Zaki
@@ -361,23 +340,37 @@ We extend our heartfelt gratitude to all the amazing contributors who have made Sawan kushwah + + + + + Suhas-Koheda +
+ Suhas Koheda +
Jay-1409
Jay shah +
- - + + + Jay-1409 + vishnuprasad2004
Vishnu Prasad Korada
+ + + sajalbatra
@@ -389,13 +382,12 @@ We extend our heartfelt gratitude to all the amazing contributors who have made PavanTeja2005
PavanTeja2005 -
- - + AE-Hertz
Abhinandan +
@@ -405,6 +397,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made Abhijit Motekar + + Navneetdadhich @@ -414,6 +408,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made + + + VinayLodhi1712 +
+ Vinay Anand Lodhi +
+ lade6501 @@ -442,13 +443,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made Aditya Bakshi - - - vaishnavipal1869 -
- vaishnavipal1869 -
- + + tanishirai @@ -479,13 +475,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made Shiva Bajpai - - - Pushpa472 -
- Pushpa Vishwakarma -
- devxMani @@ -494,6 +483,7 @@ We extend our heartfelt gratitude to all the amazing contributors who have made + meghanakn473
@@ -503,6 +493,7 @@ We extend our heartfelt gratitude to all the amazing contributors who have made +
Ayush215mb
@@ -553,13 +544,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made Sapna Kul
- - - Nikhil0-3 -
- Nikhil More -
- MutiatBash @@ -582,6 +566,7 @@ We extend our heartfelt gratitude to all the amazing contributors who have made + harjasae2001
@@ -591,6 +576,7 @@ We extend our heartfelt gratitude to all the amazing contributors who have made +
mishradev1
diff --git a/backend/controller/customer.controller.js b/backend/controller/customer.controller.js index b6195ec..e3a6886 100644 --- a/backend/controller/customer.controller.js +++ b/backend/controller/customer.controller.js @@ -123,6 +123,7 @@ async function loginCustomer(req, res) { process.env.JWT_SECRET, { expiresIn: "1h" } // Expires in 1 hour ); + req.session.user = { id: customer._id, @@ -136,6 +137,7 @@ async function loginCustomer(req, res) { }); return res.json({ + message: "Login successful", token, role: "customer", diff --git a/backend/middlewares/authCustomer.js b/backend/middlewares/authCustomer.js index eb17509..69d1032 100644 --- a/backend/middlewares/authCustomer.js +++ b/backend/middlewares/authCustomer.js @@ -1,24 +1,42 @@ const jwt = require("jsonwebtoken"); const logger = require("../config/logger"); const config = require("../config/secret"); +const Customer = require("../models/customer.model"); + // Assuming the Customer model is located here -const authenticateCustomer = (req, res, next) => { +const authenticateCustomer = async (req, res, next) => { const token = req.header("Authorization")?.split(" ")[1]; // Expecting "Bearer " - if (token) { - jwt.verify(token, config.JWT_SECRET, (err, user) => { - if (err) { - if (err.name === "TokenExpiredError") { - return res.status(401).json({ message: "Token expired" }); - } - return res.status(403).json({ message: "Invalid token" }); - } - req.user = user; - logger.info(`Customer authenticated: ${JSON.stringify(user.username)}`); - next(); - }); - } else { - res.sendStatus(401); // Unauthorized + if (!token) { + return res.status(401).json({ message: "Authorization token is missing" }); + } + + try { + // Verify token + const decoded = jwt.verify(token, config.JWT_SECRET); + + // Retrieve user from database to check verification status + const user = await Customer.findById(decoded.sub); + + if (!user) { + return res.status(404).json({ message: "User not found" }); + } + + if (!user.isVerified) { + return res.status(403).json({ message: "Account not verified" }); + } + + // If verified, attach user to request and proceed + req.user = user; + logger.info(`Customer authenticated: ${user.name}`); + next(); + + } catch (err) { + if (err.name === "TokenExpiredError") { + return res.status(401).json({ message: "Token expired" }); + } + logger.error("Token verification failed:", err); + return res.status(403).json({ message: "Invalid token" }); } }; diff --git a/backend/routes/eventRouter.js b/backend/routes/eventRouter.js index 7cdcece..1cd9d77 100644 --- a/backend/routes/eventRouter.js +++ b/backend/routes/eventRouter.js @@ -5,6 +5,7 @@ const { getEvents, deleteEvent, } = require("../controller/event.controller"); +const authenticateCustomer = require("../middlewares/authCustomer"); const router = express.Router(); @@ -24,8 +25,8 @@ router.get("/", async (req, res) => { res.status(500).json({ error: "Internal server error" }); } }); -router.post("/create", createEvent); -router.get("/all", getEvents); -router.get("/delete", deleteEvent); +router.post("/create",authenticateCustomer, createEvent); +router.get("/all",authenticateCustomer, getEvents); +router.get("/delete",authenticateCustomer, deleteEvent); module.exports = router; diff --git a/frontend/src/components/Pages/Event.jsx b/frontend/src/components/Pages/Event.jsx index d60a3fc..db47e4d 100644 --- a/frontend/src/components/Pages/Event.jsx +++ b/frontend/src/components/Pages/Event.jsx @@ -14,6 +14,8 @@ import game from '../../assets/Boardgames/carrom.gif'; import spin from '../../assets/Boardgames/spin.gif'; import MainHOC from '../MainHOC'; const daysOfWeek = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']; +import { useNavigate } from 'react-router-dom'; +import Cookies from 'js-cookie'; const months = [ 'January', 'February', @@ -31,6 +33,18 @@ const months = [ function Event() { const [events, setEvents] = useState([]); const [error, setError] = useState(null); + const navigate = useNavigate(); + + + + const handleRegisterClick = () => { + const isAuthenticated = Boolean(Cookies.get('authToken')); + + if (!isAuthenticated) { + alert("Please sign in to register for the event."); + navigate('/login'); + } + }; useEffect(() => { const fetchData = async () => { try { @@ -183,7 +197,7 @@ function Event() { ))}
-