Skip to content

Commit

Permalink
Merge branch 'main' into verified_users
Browse files Browse the repository at this point in the history
  • Loading branch information
haseebzaki-07 authored Oct 29, 2024
2 parents 4704cdd + 9056618 commit 212567c
Show file tree
Hide file tree
Showing 16 changed files with 245 additions and 61 deletions.
99 changes: 86 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</a>
</td>
<td align="center">

<a href="https://github.com/haseebzaki-07">
<img src="https://avatars.githubusercontent.com/u/147314463?v=4" width="100;" alt="haseebzaki-07"/>
<br />
<sub><b>Haseeb Zaki</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/jainaryan04">
<img src="https://avatars.githubusercontent.com/u/138214350?v=4" width="100;" alt="jainaryan04"/>
<br />
<sub><b>Aryan Ramesh Jain</b></sub>
</a>
</td>
<td align="center">

<a href="https://github.com/alo7lika">
<img src="https://avatars.githubusercontent.com/u/152315710?v=4" width="100;" alt="alo7lika"/>
<br />
Expand All @@ -274,19 +290,19 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</a>
</td>
<td align="center">
<a href="https://github.com/itznayan">
<img src="https://avatars.githubusercontent.com/u/136584376?v=4" width="100;" alt="itznayan"/>
<a href="https://github.com/tejasbenibagde">
<img src="https://avatars.githubusercontent.com/u/124677750?v=4" width="100;" alt="tejasbenibagde"/>
<br />
<sub><b>Mahera Nayan</b></sub>
<sub><b>Tejas Benibagde</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/tejasbenibagde">
<img src="https://avatars.githubusercontent.com/u/124677750?v=4" width="100;" alt="tejasbenibagde"/>
<a href="https://github.com/itznayan">
<img src="https://avatars.githubusercontent.com/u/136584376?v=4" width="100;" alt="itznayan"/>
<br />
<sub><b>Tejas Benibagde</b></sub>
<sub><b>Mahera Nayan</b></sub>
</a>
</td>
<td align="center">
Expand Down Expand Up @@ -327,27 +343,47 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</tr>
<tr>
<td align="center">

<a href="https://github.com/Suhas-Koheda">
<img src="https://avatars.githubusercontent.com/u/72063139?v=4" width="100;" alt="Suhas-Koheda"/>
<br />
<sub><b>Suhas Koheda</b></sub>
</a>
</td>
<td align="center">

<a href="https://github.com/Jay-1409">
<img src="https://avatars.githubusercontent.com/u/166749819?v=4" width="100;" alt="Jay-1409"/>
<br />
<sub><b>Jay shah</b></sub>

</a>
</td>
<td align="center">

<a href="https://github.com/Jay-1409">
<img src="https://avatars.githubusercontent.com/u/166749819?v=4" width="100;" alt="Jay-1409"/>

<a href="https://github.com/vishnuprasad2004">
<img src="https://avatars.githubusercontent.com/u/116942066?v=4" width="100;" alt="vishnuprasad2004"/>
<br />
<sub><b>Vishnu Prasad Korada</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/sajalbatra">
<img src="https://avatars.githubusercontent.com/u/125984550?v=4" width="100;" alt="sajalbatra"/>

<br />
<sub><b>Jay shah</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/PavanTeja2005">
<img src="https://avatars.githubusercontent.com/u/98730339?v=4" width="100;" alt="PavanTeja2005"/>
<br />
<sub><b>PavanTeja2005</b></sub>
</a>
</td>
<td align="center">

<a href="https://github.com/sajalbatra">
<img src="https://avatars.githubusercontent.com/u/125984550?v=4" width="100;" alt="sajalbatra"/>
<br />
Expand All @@ -359,6 +395,12 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<img src="https://avatars.githubusercontent.com/u/98730339?v=4" width="100;" alt="PavanTeja2005"/>
<br />
<sub><b>PavanTeja2005</b></sub>

<a href="https://github.com/AE-Hertz">
<img src="https://avatars.githubusercontent.com/u/93651229?v=4" width="100;" alt="AE-Hertz"/>
<br />
<sub><b>Abhinandan</b></sub>

</a>
</td>
<td align="center">
Expand All @@ -377,6 +419,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Navneet Dadhich</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/VinayLodhi1712">
<img src="https://avatars.githubusercontent.com/u/135756009?v=4" width="100;" alt="VinayLodhi1712"/>
Expand Down Expand Up @@ -421,6 +465,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Tanishi Rai</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/Picodes10">
<img src="https://avatars.githubusercontent.com/u/91375618?v=4" width="100;" alt="Picodes10"/>
Expand Down Expand Up @@ -450,14 +496,23 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</a>
</td>
<td align="center">

<a href="https://github.com/meghanakn473">
<img src="https://avatars.githubusercontent.com/u/165137755?v=4" width="100;" alt="meghanakn473"/>
<br />
<sub><b>K N Meghana</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">

<a href="https://github.com/Ayush215mb">
<img src="https://avatars.githubusercontent.com/u/154300084?v=4" width="100;" alt="Ayush215mb"/>
<br />
<sub><b>Ayush Yadav</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/smog-root">
<img src="https://avatars.githubusercontent.com/u/181578777?v=4" width="100;" alt="smog-root"/>
Expand Down Expand Up @@ -493,15 +548,15 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Stuti </b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/Sapna127">
<img src="https://avatars.githubusercontent.com/u/91309280?v=4" width="100;" alt="Sapna127"/>
<br />
<sub><b>Sapna Kul</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/MutiatBash">
<img src="https://avatars.githubusercontent.com/u/108807732?v=4" width="100;" alt="MutiatBash"/>
Expand All @@ -524,6 +579,17 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
</a>
</td>
<td align="center">

<a href="https://github.com/harjasae2001">
<img src="https://avatars.githubusercontent.com/u/83627055?v=4" width="100;" alt="harjasae2001"/>
<br />
<sub><b>Harjas Singh</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">

<a href="https://github.com/mishradev1">
<img src="https://avatars.githubusercontent.com/u/118660840?v=4" width="100;" alt="mishradev1"/>
<br />
Expand All @@ -537,6 +603,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>CHIKATLA RAKESH</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/AnushkaChouhan25">
<img src="https://avatars.githubusercontent.com/u/157525924?v=4" width="100;" alt="AnushkaChouhan25"/>
<br />
<sub><b>Anushka Chouhan</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/AliGates915">
<img src="https://avatars.githubusercontent.com/u/128673394?v=4" width="100;" alt="AliGates915"/>
Expand Down
31 changes: 28 additions & 3 deletions backend/controller/customer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -97,16 +97,16 @@ async function loginCustomer(req, res) {

try {
const customer = await Customer.findOne({ email: req.body.email });

if (!customer) {
return res.status(401).json({ error: "Invalid email or password" });
}

// Check if the customer is verified
if (!customer.isVerified) {
return res.status(403).json({ error: "Account not verified. Please verify your email." });
}

const validPassword = await bcrypt.compare(req.body.password, customer.password);

if (!validPassword) {
return res.status(401).json({ error: "Invalid email or password" });
}
Expand All @@ -123,7 +123,21 @@ async function loginCustomer(req, res) {
process.env.JWT_SECRET,
{ expiresIn: "1h" } // Expires in 1 hour
);
res.json({


req.session.user = {
id: customer._id,
name: customer.name,
};

res.cookie("authToken", token, {
maxAge: 1000 * 60 * 60,
httpOnly: true,
secure: true,
});

return res.json({

message: "Login successful",
token,
role: "customer",
Expand All @@ -135,6 +149,7 @@ async function loginCustomer(req, res) {
});
} catch (error) {
console.error("Error during login:", error);

res.status(500).json({ error: "Internal server error" });
}
}
Expand Down Expand Up @@ -165,9 +180,19 @@ async function resetPassword(req, res) {
}
}

async function logout(req, res){
req.session.destroy((err) => {
if (err) {
return res.status(500).send("Failed to log out.");
}
res.send("Logged out successfully!");
});
}

module.exports = {
createCustomer,
loginCustomer,
resetPassword,
logout,
verifyOtp
};
17 changes: 17 additions & 0 deletions backend/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const passport = require("passport");
const { handleGoogleOAuth } = require("./controller/googleOAuth.controller");
const app = express();
const port = process.env.PORT || 3000;
const session = require("express-session");
const MongoStore = require("connect-mongo");

// CORS configuration
const corsOptions = {
Expand Down Expand Up @@ -42,6 +44,21 @@ mongoose
// Initialize passport middleware
app.use(passport.initialize());

app.use(
session({
secret: process.env.SECRET_KEY,
resave: false,
saveUninitialized: false,
cookie: {
maxAge: 1000 * 60 * 60 * 24,
secure: false,
},
store: MongoStore.create({
mongoUrl: process.env.MONGO_URI,
}),
})
);

// API routes
app.use("/api", require("./routes/index"));

Expand Down
12 changes: 12 additions & 0 deletions backend/middlewares/sessionMiddleware.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
const sessionMiddleware = async (req, res, next)=>{
console.log(req.session.user);


if (req.session.user !== undefined) {
next();
} else {
res.status(401).send("Invalid session. Please log in again.");
}
}

module.exports = sessionMiddleware;
2 changes: 2 additions & 0 deletions backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@
"description": "",
"dependencies": {
"bcrypt": "^5.1.1",
"connect-mongo": "^5.1.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.0",
"express-session": "^1.18.1",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.7.0",
"nodemailer": "^6.9.15",
Expand Down
2 changes: 2 additions & 0 deletions backend/routes/customerRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
loginCustomer,
createCustomer,
resetPassword,
logout,
verifyOtp,
} = require("../controller/customer.controller");
const authenticateCustomer = require("../middlewares/authCustomer");
Expand All @@ -28,6 +29,7 @@ router.get(
);

router.post("/register", createCustomer);
router.post("/logout", logout)
router.post("/verify", verifyOtp);
router.get(
"/auth/google",
Expand Down
3 changes: 2 additions & 1 deletion backend/routes/feedbackRouter.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ const { createFeedback } = require("../controller/feedback.controller");
const router = express.Router();
const apiInfo = require("../config/api.info");
const logger = require("../config/logger"); // Import your logger
const sessionMiddleware = require("../middlewares/sessionMiddleware");

router.post("/create", createFeedback);
router.post("/create", sessionMiddleware, createFeedback);

router.get("/", (req, res) => {
try {
Expand Down
2 changes: 1 addition & 1 deletion backend/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ router.get("/", (req, res) => {

router.use("/event", eventRouter);
router.use("/admin", require("./adminRouter"));
router.use("/feedback", feedbackRouter);
router.use("/feedback", require("./feedbackRouter"));
router.use("/user", require("./customerRouter"));
router.use("/reservation", require("./reservationRouter"));
router.use("/newsletter", require("./newsletterRoute"));
Expand Down
7 changes: 4 additions & 3 deletions backend/routes/orderRouter.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
const express = require("express");
const { createOrder, getOrders, deleteOrder } = require("../controller/order.controller.js");
const sessionMiddleware = require("../middlewares/sessionMiddleware.js");

const router = express.Router();


router.post("/create/:id", createOrder);
router.get("/get/:id", getOrders);
router.delete("/delete/:id", deleteOrder);
router.post("/create/:id", sessionMiddleware, createOrder);
router.get("/get/:id", sessionMiddleware, getOrders);
router.delete("/delete/:id", sessionMiddleware, deleteOrder);

module.exports = router;
3 changes: 2 additions & 1 deletion backend/routes/reservationRouter.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
const express = require("express");
const { createReservation } = require("../controller/reservation.controller");
const sessionMiddleware = require("../middlewares/sessionMiddleware");
const router = express.Router();

router.post("/create", createReservation);
router.post("/create", sessionMiddleware, createReservation);
router.get("/", (req, res) => {
res.json({
message: "Welcome to the restaurant reservation API!",
Expand Down
Binary file added frontend/src/assets/Boardgames/CARROM.webp
Binary file not shown.
Loading

0 comments on commit 212567c

Please sign in to comment.