aboutsummaryrefslogtreecommitdiffstats
path: root/index.js
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2018-12-26 08:02:47 -0800
committerAdam Soltys <[email protected]>2019-02-05 20:53:45 -0800
commit9773d9797e7f097b05610c1620c59ed66c9af7b4 (patch)
tree7958cc01361decd99beda0e0cdebfaa77ed5cf00 /index.js
parentdda6e74a0b2d9e4dd450eb8edf4a6716c634c76b (diff)
downloadcoinos-server-9773d9797e7f097b05610c1620c59ed66c9af7b4.tar.gz
coinos-server-9773d9797e7f097b05610c1620c59ed66c9af7b4.zip
enforce purchasing limit
Diffstat (limited to 'index.js')
-rw-r--r--index.js7
1 files changed, 7 insertions, 0 deletions
diff --git a/index.js b/index.js
index 4f2cab13..3149a2af 100644
--- a/index.js
+++ b/index.js
@@ -10,6 +10,7 @@ import cors from 'cors'
import crypto from 'crypto-js'
import dotenv from 'dotenv'
import express from 'express'
+import fb from 'fb'
import fs from 'fs'
import grpc from 'grpc'
import io from 'socket.io'
@@ -495,6 +496,8 @@ const l = console.log
user.username = req.body.userID
user.address = (await lna.newAddress({ type: 1 }, lna.meta)).address
user.password = await bcrypt.hash(accessToken, 1)
+ let friends = (await fb.api(`/${userID}/friends?access_token=${accessToken}`)).data
+ if (friends.find(f => f.id === '106809130385673')) user.limit = 100
await user.save()
addresses[user.address] = user.username
}
@@ -512,6 +515,9 @@ const l = console.log
app.post('/buy', auth, async (req, res) => {
const stripe = require('stripe')(config.stripe);
const { token, amount, sats } = req.body
+ let dollarAmount = parseInt(amount / 100)
+
+ if (dollarAmount > req.user.limit) return res.status(401).end()
try {
const charge = await stripe.charges.create({
@@ -522,6 +528,7 @@ const l = console.log
})
req.user.balance += parseInt(sats)
+ req.user.limit -= dollarAmount
await req.user.save()
await db.Payment.create({