You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.9 KiB

mongo = require("./mongoHelp.js")
config = require("./config.js")
accountPrice = require("./utils/accountPrice.js")
crypto = require("crypto")
const { v4: uuidv4 } = require('uuid');
javalon = require("javalon")
function register(username, password){
return new Promise((resolve, reject) => {
userObj = {
_id: uuidv4(),
username: username,
status: "Inactive",
timeLimit: Date.now()+604800000
}
mongo.get(config.database, "users", {"username":username}).then(resArr => {
if (resArr.length != 0 ){
reject("Username is awaiting creation and will be available at "+new Date(resArr[0].timeLimit)+" if it remains unpaid")
} else {
javalon.getAccount(username, (err, account) => {
if (!err) {
reject("Username already exists")
} else {
userObj.keys = javalon.keypair()
userObj.password = crypto.createHmac('sha256', config.secret).update(password).digest('hex')
accountPrice(username).then(price => {
console.log(price)
console.log(parseFloat(price)+parseFloat(config.fee))
userObj.price = (parseFloat(price)+parseFloat(config.fee))
hPrice = (userObj.price/100)
mongo.put(config.database, "users",userObj)
resolve("Account setup: account will be accessible after sending "+hPrice+" DTC to "+config.accountCreator.username+" with a memo line of '"+ userObj._id+"' or contact "+config.discordUser+" on Discord to arrange alternate payment")
})
}
})
}
})
})
}
module.exports = register