Merge pull request #1 from Expand-sys/marketplace

Marketplace
This commit is contained in:
Expand-sys 2021-05-03 21:37:38 +10:00 committed by GitHub
commit 22a23074c6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
742 changed files with 1746 additions and 27 deletions

View file

@ -11,10 +11,11 @@ thatbeing said goodluck.
from heere is will assume you have set up the api server from heere is will assume you have set up the api server
if deploying to a serverless application make sure you se t the environmental variables forst. these are as follwos if deploying to a serverless application make sure you se t the environmental variables forst. these are as follwos
* BANKAPIURL=<your api url including http/s and the trailing slash NOT BANKF> * BANKAPIURL=your api url including http/s and the trailing slash NOT BANKF
* SECURE=<true if you have ssl on your front end host> * SECURE=true if you have ssl on your front end host
* PORT=<put the port in here> * PORT=put the port in here
* SETUP=<true when you have set the above this just gets rid of the setup page that will show if it equals false or the .env file is not fojound> * MONGO=put your mongodb url here
* SETUP=true when you have set the above this just gets rid of the setup page that will show if it equals false or the .env file is not fojound
if you are deploying on a vps then if you are deploying on a vps then
1. git clone repository 1. git clone repository
@ -22,3 +23,10 @@ if you are deploying on a vps then
1. run with your favourite node webserver if you dont know any use [pm2](https://pm2.keymetrics.io/) 1. run with your favourite node webserver if you dont know any use [pm2](https://pm2.keymetrics.io/)
1. go through set up at localhost:<port number you set earlier> 1. go through set up at localhost:<port number you set earlier>
1. restart the application and badda bim badda boom you done 1. restart the application and badda bim badda boom you done
## Marketplace
now this is getting complex :sunglasses:
the market place is new and requires monogodb until Jolly finishes his rust api marketplace and i can integrate that
set up is pretty straight forward for now, it should just work:tm: as long as you import all the minecraft blocks into the database as per the item schema,
to do this there is a bit of code at the bottom of ./routes/marketplace.js uncomment that and run that url then comment it again cause you dont want to run it twice, it will messy up your shit. i will make it a one time run route in the future.

View file

@ -14,6 +14,7 @@ const url = require('url')
const dotenv = require('dotenv'); const dotenv = require('dotenv');
const fs = require('fs'); const fs = require('fs');
let Log = require('./schemas/log.js'); let Log = require('./schemas/log.js');
const mongoose = require('mongoose')
dotenv.config(); dotenv.config();
//mongodb connection //mongodb connection
@ -64,25 +65,48 @@ app.use(expressValidator({
} }
})); }));
app.post('/setup', async function(req, res){ app.post('/setup', async function(req, res){
console.log(req.body) console.log(req.body)
let mongo = req.body.mongo; let {mongo, url, banksecure, marketplace} = req.body;
process.env.MONGO = mongo process.env.MONGO = mongo
let apiurl = 'BANKAPIURL='+req.body.url process.env.MARKETPLACE = false
process.env.BANKAPIURL = req.body.url if(marketplace){
let banksecure = 'SECURE=false' process.env.MARKETPLACE = true
}
if(!url.endsWith('/')){
url=url+"/"
}
process.env.BANKAPIURL =url
process.env.SECURE = false process.env.SECURE = false
if(req.body.secure){ if(!banksecure){
banksecure = 'SECURE=true' banksecure = false
process.env.SECURE = true process.env.SECURE = false
} }
process.env.SETUP = true process.env.SETUP = true
fs.writeFileSync('.env', apiurl+'\n'+banksecure+'\n'+mongo+'\nSETUP=true') fs.writeFileSync('.env', "BANKAPIURL="+process.env.BANKAPIURL+'\n'+"SECURE="+process.env.SECURE+'\n'+"MARKETPLACE="+process.env.MARKETPLACE+'\n'+"MONGO="+process.env.MONGO+'\nSETUP=true')
dotenv.config(); dotenv.config();
if(process.env.MARKETPLACE){
mongoose.connect(process.env.MONGO,{
useNewUrlParser: true,
useUnifiedTopology: true,
useFindAndModify: true,
});
let db = mongoose.connection;
db.once('open', function(){
console.log('Connected to MongoDB');
})
//check for DB errors
db.on('error', function(err){
console.log(err);
});
}
res.redirect('/') res.redirect('/')
}) })
app.get('/', async function(req, res){ app.get('/', async function(req, res){
if(setup==false){ if(!process.env.SETUP){
res.render('setup') res.render('setup')
}else{ }else{
@ -105,7 +129,8 @@ app.get('/', async function(req, res){
res.render('index', { res.render('index', {
user: req.session.user, user: req.session.user,
admin: req.session.admin, admin: req.session.admin,
alive: alive alive: alive,
marketplace: process.env.MARKETPLACE
}) })
} }
}); });
@ -153,8 +178,8 @@ app.get('/BankF', ensureAuthenticated, async function(req, res){
console.log(logrec.timings) console.log(logrec.timings)
console.log("query finished "+Date.now()) console.log("query finished "+Date.now())
logsent = logsent.body.value logsent = logsent.body.value
console.log(logsent)
if(logsent === 1 || logsent === -1 || logsent == null){ if(logsent == 1 || logsent == -1 || logsent == null){
logsent = undefined logsent = undefined
}else{ }else{
logsent = await logsent.filter(({ from }) => from === req.session.user) logsent = await logsent.filter(({ from }) => from === req.session.user)
@ -180,6 +205,7 @@ app.get('/BankF', ensureAuthenticated, async function(req, res){
user: req.session.user, user: req.session.user,
admin: req.session.admin, admin: req.session.admin,
sucesses: successes, sucesses: successes,
marketplace: process.env.MARKETPLACE
}) })
}); });
@ -268,12 +294,14 @@ app.post('/sendfunds', async function(req, res){
balance:balance.value, balance:balance.value,
user: req.session.user, user: req.session.user,
admin: req.session.admin, admin: req.session.admin,
marketplace: process.env.MARKETPLACE
}) })
} }
}) })
app.post('/register', async function(req, res){ app.post('/register', async function(req, res){
var {name, password, password2} = req.body; var {name, password, password2} = req.body;
let checkuser = await got(process.env.BANKAPIURL+'BankF/contains/'+name) let checkuser = await got(process.env.BANKAPIURL+'BankF/contains/'+name)
checkuser = JSON.parse(checkuser.body).value checkuser = JSON.parse(checkuser.body).value
let errors = []; let errors = [];
@ -290,7 +318,8 @@ app.post('/register', async function(req, res){
} }
if(errors[0]){ if(errors[0]){
res.render('register', { res.render('register', {
errors:errors errors:errors,
marketplace: process.env.MARKETPLACE
}) })
} else { } else {
if(postUser(name, password)){ if(postUser(name, password)){
@ -298,6 +327,7 @@ app.post('/register', async function(req, res){
res.render('login',{ res.render('login',{
errors:errors, errors:errors,
successes: successes, successes: successes,
marketplace: process.env.MARKETPLACE
}) })
} }
} }
@ -305,6 +335,7 @@ app.post('/register', async function(req, res){
errors.push({msg: "User already exists"}) errors.push({msg: "User already exists"})
res.render('register',{ res.render('register',{
errors:errors, errors:errors,
marketplace: process.env.MARKETPLACE
}) })
} }
}) })
@ -326,6 +357,7 @@ app.post('/login', async function(req, res){
} catch(err){ } catch(err){
console.log(err) console.log(err)
} }
req.session.password = password
if(adminTest.body.value == undefined){ if(adminTest.body.value == undefined){
res.redirect('/') res.redirect('/')
}else{ }else{
@ -350,7 +382,8 @@ app.post('/login', async function(req, res){
if(verified.body.value == 0){ if(verified.body.value == 0){
errors.push({msg: 'Password wrong'}) errors.push({msg: 'Password wrong'})
res.render('login',{ res.render('login',{
errors:errors errors:errors,
marketplace: process.env.MARKETPLACE
}) })
}else if(verified.body.value == 1){ }else if(verified.body.value == 1){
req.session.user = name; req.session.user = name;
@ -359,7 +392,8 @@ app.post('/login', async function(req, res){
} else { } else {
errors.push({msg: 'User not found'}) errors.push({msg: 'User not found'})
res.render('login',{ res.render('login',{
errors:errors errors:errors,
marketplace: process.env.MARKETPLACE
}) })
} }
} }
@ -377,13 +411,14 @@ app.use('/admin', admin);
let settings = require('./routes/settings'); let settings = require('./routes/settings');
app.use('/settings', settings) app.use('/settings', settings)
let marketplace = require('./routes/marketplace')
app.use('/marketplace', marketplace)
app.get('/logout', function(req, res){ app.get('/logout', function(req, res){
req.session.regenerate(function(err) { req.session.regenerate(function(err) {
res.render('login', { res.render('login', {
marketplace: process.env.MARKETPLACE
}) })
}) })
}); });
@ -393,6 +428,7 @@ app.get('/login', function(req, res){
req.session.regenerate(function(err) { req.session.regenerate(function(err) {
res.render('login', { res.render('login', {
user: req.session.user, user: req.session.user,
marketplace: process.env.MARKETPLACE
}) })
}) })
}); });
@ -401,6 +437,7 @@ app.get('/register', function(req, res){
res.render('register', { res.render('register', {
user: req.session.user, user: req.session.user,
admin: req.session.admin, admin: req.session.admin,
marketplace: process.env.MARKETPLACE
}) })
}); });

925
package-lock.json generated

File diff suppressed because it is too large Load diff

View file

@ -1,6 +1,7 @@
{ {
"dependencies": { "dependencies": {
"connect-flash": "^0.1.1", "connect-flash": "^0.1.1",
"cote": "^1.0.2",
"dotenv": "^8.2.0", "dotenv": "^8.2.0",
"express": "^4.17.1", "express": "^4.17.1",
"express-messages": "^1.0.1", "express-messages": "^1.0.1",
@ -12,6 +13,7 @@
"mongoose": "^5.12.5", "mongoose": "^5.12.5",
"path": "^0.12.7", "path": "^0.12.7",
"pug": "^3.0.2", "pug": "^3.0.2",
"socket.io": "^2.4.1",
"url": "^0.11.0", "url": "^0.11.0",
"validator": "^13.5.2" "validator": "^13.5.2"
}, },

Binary file not shown.

After

Width:  |  Height:  |  Size: 80 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 454 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,009 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 943 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 593 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 180 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 908 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 172 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 222 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 586 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 209 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 482 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 558 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 937 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 918 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 328 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 530 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 548 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 563 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 541 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 981 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 412 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 432 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 449 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 433 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 997 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 802 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 871 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 145 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 707 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 974 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 634 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 518 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 320 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 187 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 422 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 726 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 934 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 364 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 311 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 561 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 414 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 233 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 796 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 830 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 680 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 785 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 287 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 736 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 978 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 826 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 856 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 843 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 723 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1 KiB

Some files were not shown because too many files have changed in this diff Show more