Skip to content

Commit

Permalink
Merge branch 'main' into bug-GifResponsive
Browse files Browse the repository at this point in the history
  • Loading branch information
NilanchalaPanda authored Oct 16, 2024
2 parents 8570dfb + 75ecbc6 commit f3c5c6c
Show file tree
Hide file tree
Showing 18 changed files with 411 additions and 110 deletions.
118 changes: 103 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -177,48 +177,99 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Arindam</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 />
<sub><b>alolika bhowmik</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Ashwinib26">
<img src="https://avatars.githubusercontent.com/u/149402720?v=4" width="100;" alt="Ashwinib26"/>
<br />
<sub><b>Ashwini_ab</b></sub>
</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"/>
<br />
<sub><b>Mahera Nayan</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"/>
<br />
<sub><b>Tejas Benibagde</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Shirisha-16">
<img src="https://avatars.githubusercontent.com/u/148051550?v=4" width="100;" alt="Shirisha-16"/>
<br />
<sub><b>Tyarla Shirisha</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Amnyadav">
<img src="https://avatars.githubusercontent.com/u/127370497?v=4" width="100;" alt="Amnyadav"/>
<br />
<sub><b>Amnyadav</b></sub>
</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/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/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>
</tr>
<tr>
<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>Sajal Batra</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/vishnuprasad2004">
<img src="https://avatars.githubusercontent.com/u/116942066?v=4" width="100;" alt="vishnuprasad2004"/>
<a href="https://github.com/PavanTeja2005">
<img src="https://avatars.githubusercontent.com/u/98730339?v=4" width="100;" alt="PavanTeja2005"/>
<br />
<sub><b>Vishnu Prasad Korada</b></sub>
<sub><b>PavanTeja2005</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/AbhijitMotekar99">
<img src="https://avatars.githubusercontent.com/u/109235675?v=4" width="100;" alt="AbhijitMotekar99"/>
<a href="https://github.com/NilanchalaPanda">
<img src="https://avatars.githubusercontent.com/u/110488337?v=4" width="100;" alt="NilanchalaPanda"/>
<br />
<sub><b>Abhijit Motekar</b></sub>
<sub><b>Nilanchal</b></sub>
</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/AbhijitMotekar99">
<img src="https://avatars.githubusercontent.com/u/109235675?v=4" width="100;" alt="AbhijitMotekar99"/>
<br />
<sub><b>Mahera Nayan</b></sub>
<sub><b>Abhijit Motekar</b></sub>
</a>
</td>
<td align="center">
Expand All @@ -228,29 +279,59 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Navneet Dadhich</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Aditya90456">
<img src="https://avatars.githubusercontent.com/u/153073510?v=4" width="100;" alt="Aditya90456"/>
<br />
<sub><b>Aditya Bakshi</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/tanishirai">
<img src="https://avatars.githubusercontent.com/u/178164785?v=4" width="100;" alt="tanishirai"/>
<br />
<sub><b>Tanishi Rai</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Picodes10">
<img src="https://avatars.githubusercontent.com/u/91375618?v=4" width="100;" alt="Picodes10"/>
<br />
<sub><b>Sushree Manaswini Biswal</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Sourabh782">
<img src="https://avatars.githubusercontent.com/u/103349890?v=4" width="100;" alt="Sourabh782"/>
<br />
<sub><b>Sourabh Singh Rawat</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/Shiva-Bajpai">
<img src="https://avatars.githubusercontent.com/u/141490705?v=4" width="100;" alt="Shiva-Bajpai"/>
<br />
<sub><b>Shiva Bajpai</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/Sawan-Kushwah">
<img src="https://avatars.githubusercontent.com/u/138680328?v=4" width="100;" alt="Sawan-Kushwah"/>
<br />
<sub><b>Sawan kushwah </b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/devxMani">
<img src="https://avatars.githubusercontent.com/u/122438942?v=4" width="100;" alt="devxMani"/>
<br />
<sub><b>MANI </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"/>
Expand Down Expand Up @@ -286,15 +367,15 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<sub><b>Jay shah</b></sub>
</a>
</td>
</tr>
<tr>
<td align="center">
<a href="https://github.com/Mohitranag18">
<img src="https://avatars.githubusercontent.com/u/152625405?v=4" width="100;" alt="Mohitranag18"/>
<br />
<sub><b>Mohit Rana </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 Down Expand Up @@ -329,6 +410,13 @@ We extend our heartfelt gratitude to all the amazing contributors who have made
<br />
<sub><b>Vaibhav-Kumar-K-R</b></sub>
</a>
</td>
<td align="center">
<a href="https://github.com/lade6501">
<img src="https://avatars.githubusercontent.com/u/83055827?v=4" width="100;" alt="lade6501"/>
<br />
<sub><b>Vishal Lade</b></sub>
</a>
</td>
</tr>
<tbody>
Expand Down
9 changes: 8 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
MONGO_URI=enter_your_mongo_uri
EMAIL_USER=your_gmail
PORT=3000
EMAIL_PASS=your_16_digit_pass
JWT_SECRET=secret
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
43 changes: 43 additions & 0 deletions backend/config/oauth.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/* eslint-disable prettier/prettier */
const GoogleStrategy = require("passport-google-oauth20").Strategy;
const passport = require("passport");
const Customer = require("../models/customer.model"); // Adjust the path as needed
const config = require("./secret"); // Import your secrets (client ID, client secret)
console.log("config", config);
passport.use(
new GoogleStrategy(
{
clientID: process.env.GOOGLE_CLIENT_ID || config.GOOGLE_CLIENT_ID,
clientSecret:
process.env.GOOGLE_CLIENT_SECRET || config.GOOGLE_CLIENT_SECRET,
callbackURL:
process.env.NODE_ENV === "production"
? process.env.PROD_CALLBACK_URL // Use production callback URL
: process.env.CALLBACK_URL, // Use development (localhost) callback URL
},
async (accessToken, refreshToken, profile, done) => {
try {
// Extract the email from Google profile
const email = profile.emails[0].value;

// Search for the user in the database by email
let user = await Customer.findOne({ email });
if (!user) {
// If user doesn't exist, create a new user
user = new Customer({
name: profile.displayName || "Unamed User",
email: email, // Email from Google profile
});
await user.save();
}
// Return the user if exists or after creation
return done(null, user);
} catch (error) {
console.error("Error during Google authentication:", error);
return done(null, false, { message: "Authentication failed" });
}
}
)
);

module.exports = passport;
47 changes: 47 additions & 0 deletions backend/config/passport.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
// passportConfig.js
const { Strategy: JwtStrategy, ExtractJwt } = require("passport-jwt");
const passport = require("passport");
const config = require("./secret");
const Customer = require("../models/customer.model");
const Admin = require("../models/admin.model");
require("./oauth.config");

// Secret key to sign the JWT token
const secret = config.JWT_SECRET;
const opts = {
jwtFromRequest: ExtractJwt.fromAuthHeaderAsBearerToken(),
secretOrKey: process.env.JWT_SECRET || secret,
algorithms: ["HS256"],
};

passport.use(
new JwtStrategy(opts, (jwt_payload, done) => {
// jwt_payload contains the decoded token
// You can use the payload data (such as user id) to check if the user exists

const userId = jwt_payload.sub;
const role = jwt_payload.role;
const roleModelMap = {
customer: Customer,
admin: Admin,
};
const Model = roleModelMap[role];
if (Model) {
Model.findById(userId)
.then((user) => {
if (user) {
return done(null, user);
}
return done(null, false);
})
.catch((error) => {
return done(error, false);
});
} else {
// Handle unknown roles
return done(null, false);
}
})
);

module.exports = passport;
10 changes: 10 additions & 0 deletions backend/config/secret.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ const JWT_SECRET = process.env.JWT_SECRET;
const MONGO_URI = process.env.MONGO_URI;
const PORT = process.env.PORT;
const CORS_ORIGIN = process.env.CORS_ORIGIN;
const GOOGLE_CLIENT_ID = process.env.GOOGLE_CLIENT_ID;
const GOOGLE_CLIENT_SECRET = process.env.GOOGLE_CLIENT_SECRET;
const FRONTEND_URL = process.env.FRONTEND_URL;
const CALLBACK_URL = process.env.CALLBACK_URL;
const PROD_CALLBACK_URL = process.env.PROD_CALLBACK_URL;

module.exports = {
JWT_SECRET,
MONGO_URI,
PORT,
CORS_ORIGIN,
GOOGLE_CLIENT_ID,
GOOGLE_CLIENT_SECRET,
FRONTEND_URL,
CALLBACK_URL,
PROD_CALLBACK_URL,
};
18 changes: 10 additions & 8 deletions backend/controller/admin.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,20 @@ async function loginAdmin(req, res) {
}
const validPassword = await bcrypt.compare(
req.body.password,
admin.password,
admin.password
);
if (!validPassword) {
return res.status(401).json({ error: "Invalid email or password" });
}
const token = jwt.sign(
{ id: admin._id, role: "admin" },
process.env.JWT_SECRET,
{
expiresIn: "1h",
},
);
const payload = {
sub: admin._id, // User ID
name: admin.name, // Optional
role: "admin", // Optional
email: admin.email, // Optional
};
const token = jwt.sign(payload, process.env.JWT_SECRET, {
expiresIn: "1h",
});
res.json({
message: "Login successful",
token,
Expand Down
12 changes: 9 additions & 3 deletions backend/controller/customer.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,15 +56,21 @@ async function loginCustomer(req, res) {
}
const validPassword = await bcrypt.compare(
req.body.password,
customer.password,
customer.password
);
if (!validPassword) {
return res.status(401).json({ error: "Invalid email or password" });
}
const payload = {
sub: customer._id, // User ID
name: customer.name, // Optional
role: "customer", // Optional
email: customer.email, // Optional
};
const token = jwt.sign(
{ id: customer._id },
payload,
process.env.JWT_SECRET,
{ expiresIn: "1h" }, // Expires in 1 hour
{ expiresIn: "1h" } // Expires in 1 hour
);
res.json({
message: "Login successful",
Expand Down
Loading

0 comments on commit f3c5c6c

Please sign in to comment.