From 4a9ca15bbcca9a5f4a1b4de89cd5d608146b32fb Mon Sep 17 00:00:00 2001
From: "github-actions[bot]"
<41898282+github-actions[bot]@users.noreply.github.com>
Date: Tue, 29 Oct 2024 18:19:57 +0000
Subject: [PATCH 1/4] docs(contributor): contrib-readme-action has updated
readme
---
README.md | 39 ++++++++++++++++++++++++---------------
1 file changed, 24 insertions(+), 15 deletions(-)
diff --git a/README.md b/README.md
index d57a3ac..44c24b6 100644
--- a/README.md
+++ b/README.md
@@ -435,6 +435,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Vishal Lade
+
+
+
+
+ Anushka Chouhan
+
+ |
@@ -449,6 +456,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
t rahul prabhu
|
+
+
@@ -456,8 +465,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Aditya Bakshi
|
-
-
@@ -493,6 +500,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Pushpa Vishwakarma
|
+
+
@@ -500,8 +509,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Mansi Sharma
|
-
-
@@ -537,6 +544,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Vaibhav._Y
|
+
+
@@ -544,8 +553,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Vaibhav-Kumar-K-R
|
-
-
@@ -581,6 +588,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Bashua Mutiat
|
+
+
@@ -588,8 +597,6 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Mohit Rana
|
-
-
@@ -597,6 +604,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
Jai Dhingra
|
+
+
+
+
+ Vivek Prakash
+
+ |
@@ -618,13 +632,8 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
CHIKATLA RAKESH
|
-
-
-
-
- Anushka Chouhan
-
- |
+
+
From 84307de6f7129fb13abc40cb0c7c902cabab7303 Mon Sep 17 00:00:00 2001
From: harshbhar0629
Date: Wed, 30 Oct 2024 12:40:16 +0530
Subject: [PATCH 2/4] Adding functionality upload image to cloudinary
---
backend/.env.example | 6 +++++-
backend/config/cloudinary.js | 18 ++++++++++++++++++
backend/controller/admin.controller.js | 17 +++++++++++++++++
backend/controller/customer.controller.js | 15 +++++++++++++++
backend/index.js | 11 +++++++++++
backend/package.json | 2 ++
backend/utils/imageUploader.js | 17 +++++++++++++++++
frontend/src/components/Pages/Signup.jsx | 9 ++++++++-
8 files changed, 93 insertions(+), 2 deletions(-)
create mode 100644 backend/config/cloudinary.js
create mode 100644 backend/utils/imageUploader.js
diff --git a/backend/.env.example b/backend/.env.example
index 8c71fad..6339d82 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -8,4 +8,8 @@ GOOGLE_CLIENT_SECRET=your_google_client_secret
FRONTEND_URL=your_frontend_url
CALLBACK_URL=http://localhost:3000/auth/google/callback
PROD_CALLBACK_URL=https://play-cafe.vercel.app/auth/google/callback
-NODE_ENV=development
\ No newline at end of file
+NODE_ENV=development
+FOLDER_NAME = "files"
+CLOUD_NAME=""
+CLOUD_API_KEY=""
+CLOUD_SECRET=""
\ No newline at end of file
diff --git a/backend/config/cloudinary.js b/backend/config/cloudinary.js
new file mode 100644
index 0000000..5b928ec
--- /dev/null
+++ b/backend/config/cloudinary.js
@@ -0,0 +1,18 @@
+/** @format */
+
+const cloudinary = require("cloudinary").v2; //! Cloudinary is being required
+
+exports.cloudinaryConnect = () => {
+ try {
+ cloudinary.config({
+ // Configuring the Cloudinary to Upload MEDIA
+ cloud_name: process.env.CLOUD_NAME,
+ api_key: process.env.CLOUD_API_KEY,
+ api_secret: process.env.CLOUD_SECRET,
+ });
+ console.log("Cloud connect successfully")
+ } catch (error) {
+ console.log("Error in connection of cloud");
+ console.log(error.message);
+ }
+};
diff --git a/backend/controller/admin.controller.js b/backend/controller/admin.controller.js
index dbd7408..611b28c 100644
--- a/backend/controller/admin.controller.js
+++ b/backend/controller/admin.controller.js
@@ -3,6 +3,7 @@ const { z } = require("zod");
const Admin = require("../models/admin.model");
const logger = require("../config/logger");
const jwt = require("jsonwebtoken");
+const {uploadImageToCloudinary} = require("../utils/imageUploader")
// Define the schema
const adminSchema = z.object({
@@ -26,10 +27,26 @@ async function createAdmin(req, res) {
try {
const hashedPassword = await bcrypt.hash(req.body.password, 10);
+
+ const { file } = req.body;
+ let thumbnailImage;
+ let fileComming = false;
+ // Upload the Thumbnail to Cloudinary
+ if (file !== "") {
+ fileComming = true;
+ thumbnailImage = await uploadImageToCloudinary(
+ file,
+ process.env.FOLDER_NAME
+ );
+ console.log(thumbnailImage);
+ }
+
+
const admin = new Admin({
name: req.body.name,
email: req.body.email,
password: hashedPassword,
+ profilePicture: fileComming? thumbnailImage.secure_url : "null",
});
await admin.save();
res.status(201).json({ message: "Admin created successfully" });
diff --git a/backend/controller/customer.controller.js b/backend/controller/customer.controller.js
index b6195ec..b076ebb 100644
--- a/backend/controller/customer.controller.js
+++ b/backend/controller/customer.controller.js
@@ -5,6 +5,7 @@ const { z } = require("zod");
const Customer = require("../models/customer.model");
const jwt = require("jsonwebtoken");
const { sendRegisterVerificationMail } = require("../config/nodemailer");
+const { uploadImageToCloudinary } = require("../utils/imageUploader");
// Define the schema
const customerSchema = z.object({
@@ -29,6 +30,19 @@ async function createCustomer(req, res) {
const otp = crypto.randomInt(100000, 999999).toString();
const otpExpiry = new Date(Date.now() + 5 * 60 * 1000); // 5 mins from now
+ const { file } = req.body;
+ let fileComming = false;
+ let thumbnailImage;
+ if (file !== "") {
+ fileComming = true;
+ // Upload the Thumbnail to Cloudinary
+ thumbnailImage = await uploadImageToCloudinary(
+ file,
+ process.env.FOLDER_NAME
+ );
+ console.log(thumbnailImage);
+ }
+
const hashedPassword = await bcrypt.hash(req.body.password, 10);
const customer = new Customer({
name: req.body.name,
@@ -37,6 +51,7 @@ async function createCustomer(req, res) {
otp,
otpExpiry,
isVerified: false,
+ profilePicture: fileComming? thumbnailImage.secure_url: "null",
});
await customer.save();
diff --git a/backend/index.js b/backend/index.js
index 5dfeab5..9b35aef 100644
--- a/backend/index.js
+++ b/backend/index.js
@@ -11,6 +11,8 @@ const app = express();
const port = process.env.PORT || 3000;
const session = require("express-session");
const MongoStore = require("connect-mongo");
+const fileUpload = require("express-fileupload");
+const { cloudinaryConnect } = require("./config/cloudinary");
// CORS configuration
const corsOptions = {
@@ -22,6 +24,12 @@ app.use(cors(corsOptions));
app.use(express.json());
app.use('/api', newsletterRoute);
+app.use(
+ fileUpload({
+ useTempFiles: true,
+ tempFileDir: __dirname + "/tmp/",
+ })
+);
// MongoDB connection
mongoose
@@ -37,6 +45,9 @@ mongoose
process.exit(1);
});
+// call to cloud setup
+cloudinaryConnect();
+
// Enable CORS preflight for the create reservation route only
// Uncomment if needed
// app.options("/api/reservation/create", cors(corsOptions));
diff --git a/backend/package.json b/backend/package.json
index 11a318f..a59711f 100644
--- a/backend/package.json
+++ b/backend/package.json
@@ -16,10 +16,12 @@
"description": "",
"dependencies": {
"bcrypt": "^5.1.1",
+ "cloudinary": "^2.5.1",
"connect-mongo": "^5.1.0",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.0",
+ "express-fileupload": "^1.5.1",
"express-session": "^1.18.1",
"jsonwebtoken": "^9.0.2",
"mongoose": "^8.7.0",
diff --git a/backend/utils/imageUploader.js b/backend/utils/imageUploader.js
new file mode 100644
index 0000000..f9d7d18
--- /dev/null
+++ b/backend/utils/imageUploader.js
@@ -0,0 +1,17 @@
+/** @format */
+
+const cloudinary = require("cloudinary").v2;
+
+exports.uploadImageToCloudinary = async (file, folder, height, quality) => {
+ const options = { folder };
+ if (height) {
+ options.height = height;
+ }
+ if (quality) {
+ options.quality = quality;
+ }
+
+ options.resource_type = "auto";
+
+ return await cloudinary.uploader.upload(file.tempFilePath, options);
+};
diff --git a/frontend/src/components/Pages/Signup.jsx b/frontend/src/components/Pages/Signup.jsx
index 37498c3..357a37c 100644
--- a/frontend/src/components/Pages/Signup.jsx
+++ b/frontend/src/components/Pages/Signup.jsx
@@ -11,7 +11,7 @@ const Signup = () => {
const [isLoading, setIsLoading] = useState(false);
const [error, setError] = useState(null);
const [passwordStrength, setPasswordStrength] = useState(0);
- const [data, setData] = useState({ name: '', email: '', password: '' });
+ const [data, setData] = useState({ name: '', email: '', password: '', file: '' });
const [hidden, setHidden] = useState(true);
const handleChange = (e) => {
@@ -112,6 +112,13 @@ const Signup = () => {
type="text"
onChange={handleChange}
/>
+
Date: Fri, 1 Nov 2024 14:51:12 +0530
Subject: [PATCH 3/4] Update .env.example
---
backend/.env.example | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/backend/.env.example b/backend/.env.example
index 6339d82..5ba9992 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -9,7 +9,8 @@ FRONTEND_URL=your_frontend_url
CALLBACK_URL=http://localhost:3000/auth/google/callback
PROD_CALLBACK_URL=https://play-cafe.vercel.app/auth/google/callback
NODE_ENV=development
+
FOLDER_NAME = "files"
CLOUD_NAME=""
CLOUD_API_KEY=""
-CLOUD_SECRET=""
\ No newline at end of file
+CLOUD_SECRET=""
From 7c305f21d6c68d5ab5a426807ce6377886b47ee7 Mon Sep 17 00:00:00 2001
From: Harsh Bhardwaj
Date: Fri, 1 Nov 2024 14:54:34 +0530
Subject: [PATCH 4/4] Delete backend/.env.example
---
backend/.env.example | 16 ----------------
1 file changed, 16 deletions(-)
delete mode 100644 backend/.env.example
diff --git a/backend/.env.example b/backend/.env.example
deleted file mode 100644
index 5ba9992..0000000
--- a/backend/.env.example
+++ /dev/null
@@ -1,16 +0,0 @@
-MONGO_URI=
-EMAIL_USER=your_gmail
-PORT=3000
-EMAIL_PASS=your_16_digit_pass
-JWT_SECRET=secret
-GOOGLE_CLIENT_ID=your_google_client_id
-GOOGLE_CLIENT_SECRET=your_google_client_secret
-FRONTEND_URL=your_frontend_url
-CALLBACK_URL=http://localhost:3000/auth/google/callback
-PROD_CALLBACK_URL=https://play-cafe.vercel.app/auth/google/callback
-NODE_ENV=development
-
-FOLDER_NAME = "files"
-CLOUD_NAME=""
-CLOUD_API_KEY=""
-CLOUD_SECRET=""
|