Skip to content

Commit

Permalink
mail
Browse files Browse the repository at this point in the history
  • Loading branch information
GO-viper7 committed Jul 2, 2022
1 parent 909d691 commit a477e7a
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 22 deletions.
14 changes: 14 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"jsonwebtoken": "^8.5.1",
"mongoose": "^6.3.4",
"multer": "^1.4.5-lts.1",
"nodemailer": "^6.7.6",
"passport": "^0.6.0",
"passport-twitter": "^1.0.4"
}
Expand Down
74 changes: 52 additions & 22 deletions routes/shop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const adminData = require('./admin');
const router = express.Router();
const users = require('../users.json')
const jwt = require('jsonwebtoken')

const nodeMailer = require('nodemailer')

const crypto = require('crypto')
const DiscordOauth2 = require("discord-oauth2");
Expand Down Expand Up @@ -118,32 +118,62 @@ router.post('/', async (req, res, next) => {
if (cookies) {

let user = await oauth.getUser(jwt.verify(cookies, process.env.jwtSecret))
let discordUser = user
var o = 0;
if ( req.body.red == true) {
console.log('goin to red')
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)



let transporter = nodeMailer.createTransport({
host: 'smtp.gmail.com',
port: 465,
secure: true,
auth: {
user: '[email protected]',
pass: 'uivrkjacwnpzvoop'
}
else {
console.log(data)
});
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);
}
})
await new itemSchema({
id: req.body.id,
userId: user.id,
name: req.body.name,
url: req.body.url,
category: req.body.category
}).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
1 change: 1 addition & 0 deletions views/shop.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@
"name" : n,
"description" : des,
"cost" : a - q,
"realCost" : q,
"red" : true,
"stock" : r,
"arr" : ary,
Expand Down

0 comments on commit a477e7a

Please sign in to comment.