diff --git a/README.md b/README.md index fb3af533..5624a029 100644 --- a/README.md +++ b/README.md @@ -126,26 +126,26 @@ Special thanks to our amazing mentors who are guiding this project! 🙌 - - sajalbatra + + vishnuprasad2004
- Sajal Batra + Vishnu Prasad Korada
- - vishnuprasad2004 + + sajalbatra
- Vishnu Prasad Korada + Sajal Batra
- - Navneetdadhich + + AbhijitMotekar99
- Navneet Dadhich + Abhijit Motekar
@@ -156,10 +156,10 @@ Special thanks to our amazing mentors who are guiding this project! 🙌 - - AbhijitMotekar99 + + Navneetdadhich
- Abhijit Motekar + Navneet Dadhich
@@ -185,6 +185,13 @@ Special thanks to our amazing mentors who are guiding this project! 🙌 Jai Dhingra + + + Mohitranag18 +
+ Mohit Rana +
+ MutiatBash @@ -199,6 +206,13 @@ Special thanks to our amazing mentors who are guiding this project! 🙌 Sapna Kul + + + Shiva-Bajpai +
+ Shiva Bajpai +
+ Syed-Farazuddin @@ -206,6 +220,8 @@ Special thanks to our amazing mentors who are guiding this project! 🙌 Syed Faraz + + Vaibhav-Kumar-K-R diff --git a/backend/.env.example b/backend/.env.example index c8cf3d4e..b547b64e 100644 --- a/backend/.env.example +++ b/backend/.env.example @@ -1 +1,3 @@ -MONGO_URI=enter_your_mongo_uri \ No newline at end of file +MONGO_URI=enter_your_mongo_uri +EMAIL_USER=your_gmail +EMAIL_PASS=your_16_digit_pass \ No newline at end of file diff --git a/backend/config/nodemailer.js b/backend/config/nodemailer.js new file mode 100644 index 00000000..ad25a5c1 --- /dev/null +++ b/backend/config/nodemailer.js @@ -0,0 +1,50 @@ +require("dotenv").config(); +const nodemailer = require("nodemailer"); +const logger = require('./logger'); + +// Create a Nodemailer transporter using SMTP +const transporter = nodemailer.createTransport({ + service: "gmail", // or your preferred email service + auth: { + user: process.env.EMAIL_USER, + pass: process.env.EMAIL_PASS, + }, +}); + +// Function to send reservation confirmation via email +exports.sendReservationConfirmation = async (email, reservationDetails) => { + const { reservationDate, guests, time } = reservationDetails; + + // Construct the email content + const emailText = ` + Dear Customer, + + We are pleased to confirm your reservation. Here are the details of your reservation: + + Reservation Date: ${reservationDate} + Number of Guests: ${guests} + Reservation Time: ${time} + + Thank you for choosing our service. We look forward to hosting you. + + Best regards, + PlayCafe + `; + + try { + await transporter.sendMail({ + from: process.env.EMAIL_USER, + to: email, + subject: "Reservation Confirmation", + text: emailText, + }); + logger.info('Reservation confirmation sent successfully via email', { email }); + } catch (error) { + logger.error('Failed to send reservation confirmation email', { error, email }); + if (error.code === 'ECONNREFUSED') { + throw new Error('Failed to connect to email server. Please try again later.'); + } else { + throw new Error(`Failed to send reservation confirmation email: ${error.message}`); + } + } +}; \ No newline at end of file diff --git a/backend/controller/reservation.controller.js b/backend/controller/reservation.controller.js index 4ee00658..f86e079f 100644 --- a/backend/controller/reservation.controller.js +++ b/backend/controller/reservation.controller.js @@ -1,13 +1,15 @@ const { z } = require("zod"); const Reservation = require("../models/reservation.model"); -const logger = require("../config/logger"); // Import your logger +const logger = require("../config/logger"); +const { sendReservationConfirmation } = require("../config/nodemailer"); // Import your email function // Define the Zod schema for reservation validation const reservationSchema = z.object({ guests: z.string(), date: z.string(), time: z.string(), -}); + email: z.string().email(), // Include email validation in the schema +}).strict(); // Disallow unknown keys async function createReservation(req, res) { try { @@ -25,8 +27,22 @@ async function createReservation(req, res) { }); } + // Create the reservation in the database const reservation = await Reservation.create(validationResult.data); + // Send a confirmation email + try { + const { email, date, guests, time } = validationResult.data; + await sendReservationConfirmation(email, { reservationDate: date, guests, time }); + logger.info(`Reservation confirmation email sent to ${email}`); + } catch (emailError) { + logger.error("Error sending reservation confirmation email:", { + message: emailError.message, + }); + // Email error should not block the main reservation process, so no need to return a failure response + } + + // Send the success response res.status(201).json({ success: true, message: "Reservation created successfully", @@ -48,4 +64,4 @@ async function createReservation(req, res) { module.exports = { createReservation, -}; +}; \ No newline at end of file diff --git a/backend/package.json b/backend/package.json index 2275182a..cf18051e 100644 --- a/backend/package.json +++ b/backend/package.json @@ -16,6 +16,7 @@ "dotenv": "^16.4.5", "express": "^4.21.0", "mongoose": "^8.7.0", + "nodemailer": "^6.9.15", "validator": "^13.12.0", "winston": "^3.14.2", "zod": "^3.23.8" diff --git a/frontend/src/App.jsx b/frontend/src/App.jsx index ff0cd993..17de1827 100644 --- a/frontend/src/App.jsx +++ b/frontend/src/App.jsx @@ -4,22 +4,25 @@ import "./App.css"; import Navbar from "../src/components/Shared/Navbar"; import Footer from "../src/components/Shared/Footer"; import { Outlet } from "react-router-dom"; - +import { AuthProvider } from './components/Shared/AuthContext'; import { KindeProvider } from "@kinde-oss/kinde-auth-react"; function App() { return ( + - - -