Migrated mods to mongo & allowed add new mods
This commit is contained in:
parent
cb6e84dab2
commit
9914018163
10
index.js
10
index.js
@ -12,8 +12,6 @@ app.use(bodyParser.json(),function (req, res, next) {
|
|||||||
next()
|
next()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
app.get('/status/:status', function (req, res) {
|
app.get('/status/:status', function (req, res) {
|
||||||
list.getStatus(req.params.status).then(r => {
|
list.getStatus(req.params.status).then(r => {
|
||||||
res.send(JSON.stringify(r))
|
res.send(JSON.stringify(r))
|
||||||
@ -32,4 +30,12 @@ app.post('/submit', function (req, res) {
|
|||||||
res.send(JSON.stringify(r))
|
res.send(JSON.stringify(r))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
app.post('/approve', function (req, res) {
|
||||||
|
console.log(req.body)
|
||||||
|
list.approveUser(req.body).then(r => {
|
||||||
|
res.send(JSON.stringify(r))
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
app.listen(3000)
|
app.listen(3000)
|
||||||
|
@ -1,14 +1,15 @@
|
|||||||
const fetch = require('node-fetch')
|
const fetch = require('node-fetch')
|
||||||
const secp256k1 = require('secp256k1')
|
const secp256k1 = require('secp256k1')
|
||||||
const bs58 = require('base-x')("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
|
const bs58 = require('base-x')("123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz")
|
||||||
const allowedUsers = require("./users.js")
|
|
||||||
var mongo = require("./mongoHelp.js")
|
var mongo = require("./mongoHelp.js")
|
||||||
|
|
||||||
|
|
||||||
async function verifyMsg (obj, username) {
|
async function verifyMsg (obj) {
|
||||||
if (!allowedUsers.includes(obj.sender)) {
|
userLookup = await mongo.get("list","allowedUsers",{user:obj.sender})
|
||||||
|
senderProtectionCheck = await mongo.get("list","allowedUsers",{user:obj.user})
|
||||||
|
if (userLookup.length == 0 ) {
|
||||||
return {"Message": "User Not Allowed"}
|
return {"Message": "User Not Allowed"}
|
||||||
} else if (allowedUsers.includes(username)) {
|
} else if (senderProtectionCheck.length != 0) {
|
||||||
return {"Message": "Can't modify trusted users"}
|
return {"Message": "Can't modify trusted users"}
|
||||||
} else {
|
} else {
|
||||||
result = await fetch("https://avalon.d.tube/account/"+obj.sender)
|
result = await fetch("https://avalon.d.tube/account/"+obj.sender)
|
||||||
@ -32,17 +33,6 @@ async function verifyMsg (obj, username) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// {
|
|
||||||
// "user": "bigbootybitch",
|
|
||||||
// "status": "black",
|
|
||||||
// "reason": "1",
|
|
||||||
// "sender": "nannal",
|
|
||||||
// "ts": 1602024774158,
|
|
||||||
// "hash": "e5eb92c035c2528af5311998d14bf0be3ced0e87505c8f6481ce7ca63148b974",
|
|
||||||
// "signature": "bjNjRSnuJokydPzGCKZy7kExDeAT8mUS3iCzRzQR3y5owaBh1Mhh2UyPLHqR3bzxsK6fw13JtvCz65exPr2JsGB"
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
list = {
|
list = {
|
||||||
getStatus: async (status) => {
|
getStatus: async (status) => {
|
||||||
return await mongo.get("list","list",{"status": status})
|
return await mongo.get("list","list",{"status": status})
|
||||||
@ -55,19 +45,68 @@ list = {
|
|||||||
ver = await verifyMsg(obj)
|
ver = await verifyMsg(obj)
|
||||||
if (ver == true) {
|
if (ver == true) {
|
||||||
console.log(obj)
|
console.log(obj)
|
||||||
res = await mongo.get("list","list",{"user": obj.user})
|
limitedObj={
|
||||||
if (res.length > 0 ){
|
user: obj.user,
|
||||||
mongo.update("list","list",{"user": obj.user}, obj)
|
status: obj.status,
|
||||||
} else {
|
reason: obj.reason,
|
||||||
mongo.put("list","list", obj)
|
sender: obj.sender,
|
||||||
|
ts: obj.ts,
|
||||||
|
hash: obj.hash,
|
||||||
|
signature: obj.signature,
|
||||||
}
|
}
|
||||||
mongo.update("list","list",{"user": obj.user}, obj)
|
res = await mongo.get("list","list",{"user": limitedObj.user})
|
||||||
|
if (res.length > 0 ){
|
||||||
|
if (limitedObj.sender == res.sender){
|
||||||
|
mongo.update("list","list",{"user": limitedObj.user}, limitedObj)
|
||||||
|
} else {
|
||||||
|
return {"Message": "This user is controlled by "+res.sender+" contact them to modify this entry, in an emergency contant nannal"}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
mongo.put("list","list", limitedObj)
|
||||||
|
}
|
||||||
|
mongo.update("list","list",{"user": limitedObj.user}, limitedObj)
|
||||||
return {"Message":"Success"}
|
return {"Message":"Success"}
|
||||||
} else {
|
} else {
|
||||||
return ver
|
return ver
|
||||||
}
|
}
|
||||||
|
|
||||||
},
|
},
|
||||||
|
approveUser: async (obj) => {
|
||||||
|
ver = await verifyMsg(obj)
|
||||||
|
if (ver == true) {
|
||||||
|
console.log(obj)
|
||||||
|
limitedObj={
|
||||||
|
user: obj.user,
|
||||||
|
sender: obj.sender,
|
||||||
|
ts: obj.ts,
|
||||||
|
hash: obj.hash,
|
||||||
|
signature: obj.signature,
|
||||||
|
}
|
||||||
|
res = await mongo.get("list","allowedUsers",{"user": limitedObj.user})
|
||||||
|
if (res.length > 0 ){
|
||||||
|
return {"message":"User already approved by "+res.sender}
|
||||||
|
} else {
|
||||||
|
mongo.put("list","allowedUsers", limitedObj)
|
||||||
|
return {"Message":"Success"}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
} else {
|
||||||
|
return ver
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
verifyUser: async (obj) => {
|
||||||
|
ver = await verifyMsg(obj)
|
||||||
|
if (ver == true) {
|
||||||
|
limitedObj ={
|
||||||
|
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
return ver
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = list
|
module.exports = list
|
||||||
|
Loading…
Reference in New Issue
Block a user