-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
56 changed files
with
2,200 additions
and
841 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,8 @@ clientSecret = 'OdbZvWky-P8fYi_lMcbh_49Y2L_f4S0D' | |
jwtSecret = 'e10a181e3fe2af173d70cb8f6b2c331ecd160647' | ||
consumer_key = ftzX3tbaEkbhhW71HtCzHCeLj | ||
consumer_secret = 2KyRsGSlscIqPrwWUFy369aDLchm3sVk4JzjUXsK0IsDg1zUEW | ||
websiteURL = "https://dashboard-77.herokuapp.com" | ||
websiteURL = "http://dashboard-77.herokuapp.com" | ||
mailId = "[email protected]" | ||
mailAuthor = Marketplace | ||
mailPassword = uivrkjacwnpzvoop | ||
mailPassword = uivrkjacwnpzvoop | ||
discordURI = https://discord.com/oauth2/authorize?client_id=978339805496750150&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fdiscord&response_type=code&scope=identify%20guilds&state=d09f2a3573ba091d8fa8fbe4796dcecf |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
[ | ||
[ | ||
{"userId": "761167079171686400"}, | ||
{"userId": "268380828734717952"}, | ||
{"userId": "532177714203852800"}, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
const productSchema = require('../schemas/product-schema'); | ||
const categorySchema = require('../schemas/category-schema'); | ||
const users = require('../admins.json') | ||
const DiscordOauth2 = require("discord-oauth2"); | ||
require("dotenv").config(); | ||
const oauth = new DiscordOauth2({ | ||
clientId: process.env.clientId, | ||
clientSecret: process.env.clientSecret, | ||
redirectUri: `${process.env.websiteURL}/discord`, | ||
}); | ||
const jwt = require('jsonwebtoken') | ||
|
||
|
||
|
||
const getAdminProfile = async (req, res, next) => { | ||
let cookies = req.cookies.get('key') | ||
if (cookies == undefined) { | ||
return res.redirect('/') | ||
} | ||
next() | ||
} | ||
|
||
|
||
const getAdminCategory = async (req, res, next) => { | ||
let result1 = await categorySchema.find({}) | ||
if (result1.length == 0) { | ||
await new categorySchema({ | ||
categoryOne: 'cat1', | ||
categoryTwo: 'cat2', | ||
categoryThree: 'cat3', | ||
flag: 1 | ||
}).save() | ||
} | ||
next() | ||
} | ||
|
||
|
||
|
||
const getAdmin = async (req, res, next) => { | ||
try { | ||
let user = await oauth.getUser(jwt.verify(req.cookies.get('key'), process.env.jwtSecret)) | ||
users.forEach(x => { | ||
if (x.userId == user.id) { | ||
next() | ||
} | ||
}) | ||
// return res.redirect('/') | ||
}catch (error) { | ||
console.log(error) | ||
return res.redirect('/logout') | ||
} | ||
|
||
} | ||
|
||
|
||
|
||
const getAdminProduct = async (req, res, next) => { | ||
try { | ||
let result = await productSchema.find({}) | ||
let result1 = await categorySchema.find({}) | ||
return res.render('add-product', {prod: result, cats: result1, products: JSON.stringify(result)}); | ||
}catch (error) { | ||
console.log(error) | ||
return res.redirect('/logout') | ||
} | ||
} | ||
|
||
|
||
|
||
module.exports = { | ||
getAdminProfile, getAdminCategory, getAdmin, getAdminProduct | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
require("dotenv").config(); | ||
const express = require('express'); | ||
const chalk = require('chalk'); | ||
const router = express.Router(); | ||
const crypto = require("crypto"); | ||
const users = require('../admins.json') | ||
const mails = require('../mailIds.json') | ||
const jwt = require('jsonwebtoken') | ||
const nodeMailer = require('nodemailer') | ||
const categorySchema = require('../schemas/category-schema'); | ||
const DiscordOauth2 = require("discord-oauth2"); | ||
const oauth = new DiscordOauth2({ | ||
clientId: process.env.clientId, | ||
clientSecret: process.env.clientSecret, | ||
redirectUri: `${process.env.websiteURL}/discord`, | ||
}); | ||
const transporter = nodeMailer.createTransport({ | ||
host: 'smtp.gmail.com', | ||
port: 465, | ||
secure: true, | ||
auth: { | ||
user: process.env.mailId, | ||
pass: process.env.mailPassword | ||
} | ||
}); | ||
const profileSchema = require('../schemas/profile-schema'); | ||
const itemSchema = require('../schemas/item-schema'); | ||
const productSchema = require('../schemas/product-schema'); | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
const getCat = async (req, res, next) => { | ||
let result = await categorySchema.find({}) | ||
if (result.length == 0) { | ||
await new categorySchema({ | ||
categoryOne: 'cat1', | ||
categoryTwo: 'cat2', | ||
categoryThree: 'cat3', | ||
flag: 1 | ||
}).save() | ||
} | ||
next() | ||
} | ||
|
||
|
||
const getFirst = async (req, res, next) => { | ||
if (req.cookies.get('first') == undefined) { | ||
res.cookie("cat", `cat`, {httpOnly: false, overwrite: true}) | ||
res.cookie("fill", false , {httpOnly: false, overwrite: true}) | ||
res.cookie("inv-cat", 'cat' , {httpOnly: false, overwrite: true}) | ||
res.cookies.set("first", 'permanent') | ||
} | ||
next() | ||
} | ||
|
||
|
||
const chooseCat = async (req, res, next) => { | ||
let result = await productSchema.find({}) | ||
if (req.cookies.get('cat') == undefined) | ||
k = result.filter(x => x.category == x.category) | ||
else | ||
k = result.filter(x => x.category == (`${req.cookies.get('cat')}` == 'cat' ? x.category : `${req.cookies.get('cat')}`) ) | ||
req.products = k | ||
next() | ||
} | ||
|
||
const getProfile = async (req, res, next) => { | ||
let cookies = req.cookies.get('key') | ||
let result = await categorySchema.find({}) | ||
if (cookies == undefined) { | ||
return res.status(200).render('shop', {prod: req.products, prof: '', url: process.env.discordURI, user: '', coins: '', bool: '', inv: '', cats: result, unique: ''}) | ||
} | ||
else { | ||
next() | ||
} | ||
} | ||
|
||
|
||
const getVerified = async (req, res, next) => { | ||
try { | ||
let result = await categorySchema.find({}) | ||
let uniquePremItems=[]; | ||
let user = await oauth.getUser(jwt.verify(req.cookies.get('key'), process.env.jwtSecret)) | ||
itemSchema.find({userId: user.id, premium: true}, (err, data) => { | ||
if (err) { | ||
console.log(err) | ||
} | ||
data.forEach(g => { | ||
uniquePremItems.push({name: g.itemName, category: g.category}) | ||
}) | ||
}) | ||
const coins = profileSchema.findOne({userId: user.id}, async (err, data) => { | ||
if (err) { | ||
console.log(err) | ||
} | ||
if (data == null) { | ||
return res.redirect('/logout') | ||
} | ||
else { | ||
return res.render('shop', {prod: req.products, user: user.username, id : user.id, url: process.env.discordURI, coins: data.OctaCreds, prof: JSON.stringify(data), bool: '', ids: users, cats: result, unique: JSON.stringify(uniquePremItems)}) | ||
} | ||
}) | ||
}catch (err) { | ||
console.log(err) | ||
return res.redirect('/logout') | ||
} | ||
}; | ||
|
||
|
||
|
||
|
||
|
||
|
||
|
||
const checkUnique = async (req, res, next) => { | ||
try { | ||
if ( req.body.red == true) { | ||
let user = await oauth.getUser(jwt.verify(req.cookies.get('key'), process.env.jwtSecret)) | ||
itemSchema.countDocuments({userId: user.id, premium: true, category: req.body.category, itemName: req.body.name}, async (err, count) => { | ||
if (err) { | ||
console.log(err) | ||
} | ||
if (count > 0) { | ||
return res.redirect('/') | ||
} | ||
else { | ||
next() | ||
} | ||
}) | ||
} | ||
}catch (err) { | ||
console.log(err) | ||
return res.redirect('/logout') | ||
} | ||
next() | ||
|
||
} | ||
|
||
|
||
|
||
const sendMail = async (req, res, next) => { | ||
try{ | ||
const mailList = [] | ||
mails.forEach(mail => { | ||
mailList.push(mail.mailId) | ||
}) | ||
const discordUser = await oauth.getUser(jwt.verify(req.cookies.get('key'), process.env.jwtSecret)) | ||
const mailOptions = { | ||
from: `"${process.env.mailAuthor}" ${process.env.mailId}`, | ||
to: mailList, | ||
subject: 'Purchase from Marketplace', | ||
text: req.body.body, | ||
html: `<b> ${discordUser.username}#${discordUser.discriminator} purchased ${req.body.name} worth of ${req.body.realCost} coins</b>` | ||
}; | ||
transporter.sendMail(mailOptions, (error, info) => { | ||
if (error) { | ||
throw new Error('Error in sending mail') | ||
} | ||
console.log('Message %s sent: %s', info.messageId, info.response); | ||
}); | ||
}catch (err) { | ||
console.log(err) | ||
return res.redirect('/logout') | ||
} | ||
} | ||
|
||
|
||
|
||
const buyProduct = async (req, res, next) => { | ||
try { | ||
let user = await oauth.getUser(jwt.verify(req.cookies.get('key'), process.env.jwtSecret)) | ||
profileSchema.findOneAndUpdate({userId: user.id}, {OctaCreds : req.body.cost}, null, async (err, data) => { | ||
if (err) { | ||
console.log(err) | ||
} | ||
}) | ||
productSchema.findOneAndUpdate({id: req.body.id}, {stock : req.body.stock-1}, null, async (err, data) => { | ||
if (err) { | ||
console.log(err) | ||
} | ||
}) | ||
let arr = await profileSchema.findOne({userId: user.id}) | ||
await new itemSchema({ | ||
id: req.body.id, | ||
userId: user.id, | ||
orderId: crypto.randomBytes(10).toString("hex"), | ||
userName: `${user.username}#${user.discriminator}`, | ||
cost: req.body.cost, | ||
itemName: req.body.name.trim(), | ||
url: req.body.url, | ||
category: req.body.category.trim(), | ||
premium: req.body.premium!==undefined ? req.body.premium : false, | ||
order: false, | ||
wallet: arr.wallet, | ||
name: arr.name, | ||
gender: arr.gender, | ||
country: arr.country, | ||
zipCode: arr.zipCode, | ||
houseNumber: arr.houseNumber, | ||
city: arr.city, | ||
streetName: arr.streetName | ||
}).save() | ||
}catch (err) { | ||
console.log(err) | ||
return res.redirect('/logout') | ||
} | ||
next() | ||
} | ||
|
||
|
||
module.exports = { | ||
getCat,buyProduct,sendMail,checkUnique,getVerified,getProfile,chooseCat,getFirst | ||
}; |
Oops, something went wrong.