Skip to content

Commit

Permalink
Toggle
Browse files Browse the repository at this point in the history
  • Loading branch information
GO-viper7 committed Jul 3, 2022
1 parent a477e7a commit 0053f5b
Show file tree
Hide file tree
Showing 13 changed files with 293 additions and 94 deletions.
Binary file added public/assets/1656777546077Viper.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/1656829345362mempo5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/1656829605144mempo5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/1656829827932mempo5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added public/assets/1656829881495mempo5.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 31 additions & 3 deletions routes/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const rootDir = require('../util/path');
const router = express.Router();
const fs = require('fs');
const productSchema = require('../schemas/product-schema');
const categorySchema = require('../schemas/category-schema');
const users = require('../users.json')
const DiscordOauth2 = require("discord-oauth2");
require("dotenv").config();
Expand Down Expand Up @@ -61,12 +62,22 @@ router.get('/add-product', async (req, res, next) => {

if (cookies) {
var result = await productSchema.find({})
//console.log(result)
var result1 = await categorySchema.find({})
if (result1.length == 0) {
await new categorySchema({
categoryOne: 'cat1',
categoryTwo: 'cat2',
categoryThree: 'cat3',
flag: 1
}).save()
}
result1 = await categorySchema.find({})

let user = await oauth.getUser(jwt.verify(cookies, process.env.jwtSecret))
users.forEach(x => {

if (x.userId == user.id) {
return res.render('add-product', {prod: result});
return res.render('add-product', {prod: result, cats: result1});
}

})
Expand Down Expand Up @@ -116,6 +127,22 @@ router.post('/add-product', upload.single('file'), async (req, res, next) => {
})
return
}
if ( req.body.catEdit == true ) {

await categorySchema.updateOne({categoryOne: req.body.oldCatOne}, {categoryOne: req.body.oneName})
await categorySchema.updateOne({categoryTwo: req.body.oldCatTwo}, {categoryTwo: req.body.twoName})
let res = await categorySchema.updateOne({categoryThree: req.body.oldCatThree}, {categoryThree: req.body.threeName})
console.log(res)

await productSchema.updateMany({category: req.body.oldCatOne}, {category : req.body.oneName })
await productSchema.updateMany({category: req.body.oldCatTwo}, {category : req.body.twoName })
res = await productSchema.updateMany({category: req.body.oldCatThree}, {category : req.body.threeName })
console.log(res)


return

}
console.log(req.file)
if ( req.file == undefined) {
return;
Expand All @@ -134,7 +161,8 @@ router.post('/add-product', upload.single('file'), async (req, res, next) => {
stock : Number(req.body.stock),
name : req.body.name,
category : req.body.cat,
url : req.file.filename
url : req.file.filename,
premium : req.body.premium!==undefined ? req.body.premium : false
}).save()
});
return;
Expand Down
125 changes: 70 additions & 55 deletions routes/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const router = express.Router();
const users = require('../users.json')
const jwt = require('jsonwebtoken')
const nodeMailer = require('nodemailer')

const categorySchema = require('../schemas/category-schema');
const crypto = require('crypto')
const DiscordOauth2 = require("discord-oauth2");
const oauth = new DiscordOauth2({
Expand Down Expand Up @@ -47,7 +47,15 @@ const { UserCollection } = require('disco-oauth/lib/types');


router.get('/', async (req, res, next) => {

var result1 = await categorySchema.find({})
if (result1.length == 0) {
await new categorySchema({
categoryOne: 'cat1',
categoryTwo: 'cat2',
categoryThree: 'cat3',
flag: 1
}).save()
}
if (req.cookies.get('first') == undefined) {

res.cookie("cat", `cat`, {httpOnly: false, overwrite: true})
Expand Down Expand Up @@ -88,7 +96,7 @@ router.get('/', async (req, res, next) => {
//console.log(result)
k = result.filter(x => x.category == (`${req.cookies.get('cat')}` == 'cat' ? x.category : `${req.cookies.get('cat')}`) )
}
return res.render('shop', {prod: k, user: user.username, id : user.id, url: url, coins: o, bool: '', ids: users, inv : invis})
return res.render('shop', {prod: k, user: user.username, id : user.id, url: url, coins: o, bool: '', ids: users, inv : invis, cats: result1})
})

}
Expand All @@ -103,7 +111,7 @@ router.get('/', async (req, res, next) => {
//console.log(result)
k = result.filter(x => x.category == (`${req.cookies.get('cat')}` == 'cat' ? x.category : `${req.cookies.get('cat')}`) )
}
return res.render('shop', {prod: k, url: url, user: '', coins: '', bool: '', inv: ''})
return res.render('shop', {prod: k, url: url, user: '', coins: '', bool: '', inv: '', cats: result1})
}

});
Expand All @@ -113,7 +121,7 @@ router.get('/', async (req, res, next) => {


router.post('/', async (req, res, next) => {
// console.log( req.body)
//console.log( req.body)
let cookies = req.cookies.get('key')
if (cookies) {

Expand All @@ -123,57 +131,64 @@ router.post('/', async (req, res, next) => {
if ( req.body.red == true) {
console.log('goin to red')



let transporter = nodeMailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'uivrkjacwnpzvoop'
}
});
let mailOptions = {
from: '"GoViper" <[email protected]>',
to: ['[email protected]'],
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) {
return console.log(error);
itemSchema.countDocuments({userId: user.id, premium: true, id: req.body.id}, async (err, count) => {
console.log(count)
if (count > 0) {
return res.redirect('/')
}
else {
let transporter = nodeMailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'uivrkjacwnpzvoop'
}
});
let mailOptions = {
from: '"GoViper" <[email protected]>',
to: ['[email protected]'],
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) {
return console.log(error);
}
console.log('Message %s sent: %s', info.messageId, info.response);
});



profileSchema.findOneAndUpdate({userId: user.id}, {OctaCreds : req.body.cost}, null, async (err, data) => {
if (err) {
console.log(err)
}
else {
//console.log(data)
}
})
productSchema.findOneAndUpdate({id: req.body.id}, {stock : req.body.stock-1}, null, async (err, data) => {
if (err) {
console.log(err)
}
else {
//console.log(data)
}
})
await new itemSchema({
id: req.body.id,
userId: user.id,
name: req.body.name,
url: req.body.url,
category: req.body.category,
premium: req.body.premium!==undefined ? req.body.premium : false
}).save()
}
console.log('Message %s sent: %s', info.messageId, info.response);
});



profileSchema.findOneAndUpdate({userId: user.id}, {OctaCreds : req.body.cost}, null, async (err, data) => {
if (err) {
console.log(err)
}
else {
console.log(data)
}
})
productSchema.findOneAndUpdate({id: req.body.id}, {stock : req.body.stock-1}, null, async (err, data) => {
if (err) {
console.log(err)
}
else {
console.log(data)
}
})
await new itemSchema({
id: req.body.id,
userId: user.id,
name: req.body.name,
url: req.body.url,
category: req.body.category
}).save()
})
}
}
});
Expand Down
21 changes: 21 additions & 0 deletions schemas/category-schema.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
const mongoose = require('mongoose')

const categorySchema = mongoose.Schema({

categoryOne: {
type: String
},

categoryTwo: {
type: String
},

categoryThree: {
type: String
},
flag: {
type: String
}
})

module.exports = mongoose.model('cats', categorySchema)
6 changes: 6 additions & 0 deletions schemas/item-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ const itemSchema = mongoose.Schema({
userId: {
type: String,
},
id : {
type: Number,
},
name: {
type: String,
},
Expand All @@ -18,6 +21,9 @@ const itemSchema = mongoose.Schema({
},
description : {
type: String,
},
premium : {
type: Boolean,
}
})

Expand Down
3 changes: 3 additions & 0 deletions schemas/product-schema.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ const productSchema = mongoose.Schema({
},
description : {
type: String,
},
premium : {
type: Boolean,
}
})

Expand Down
Loading

0 comments on commit 0053f5b

Please sign in to comment.