From 9773d9797e7f097b05610c1620c59ed66c9af7b4 Mon Sep 17 00:00:00 2001 From: Adam Soltys Date: Wed, 26 Dec 2018 08:02:47 -0800 Subject: enforce purchasing limit --- index.js | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'index.js') 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({ -- cgit v1.2.3