forked from apxtri/apxtrib
46 lines
1.2 KiB
JavaScript
46 lines
1.2 KiB
JavaScript
const bcrypt = require("bcrypt");
|
|
const fs = require("fs-extra");
|
|
const glob = require("glob");
|
|
const moment = require("moment");
|
|
const jwt = require("jwt-simple");
|
|
const UUID = require("uuid");
|
|
const conf = require(`${process.env.dirtown}/conf.json`);
|
|
const Checkjson = require(`./Checkjson.js`);
|
|
|
|
const Towns = {};
|
|
Towns.changeowner = (newowner, requestby) => {
|
|
/**
|
|
*
|
|
*/
|
|
if (!fs.existsSync(`./nationchains/pagans/itm/${newowner}.json`)) {
|
|
return {
|
|
status: 404,
|
|
ref: "towns",
|
|
msg: "newownerdoesnotexist",
|
|
data: { alias: newowner },
|
|
};
|
|
}
|
|
if (!conf.mayorId || conf.mayorId == requestby) {
|
|
// update object town + town/conf.json + setup_xx.json
|
|
conf.mayorId = newowner;
|
|
fs.outputJsonSync(`${process.env.dirtown}/conf.json`, conf);
|
|
const setup = fs.readJSONSync(`${dirapi}/adminapi/www/adminapx/conf/setup_xx.json`)
|
|
setup.mayorId=newowner;
|
|
fs.outputJsonSync(`${dirapi}/adminapi/www/adminapx/conf/setup_xx.json`,setup);
|
|
return {
|
|
status: 200,
|
|
ref: "towns",
|
|
msg: "newownerchangesusccess",
|
|
data: { alias: newowner },
|
|
};
|
|
}
|
|
return {
|
|
status: 403,
|
|
ref: "towns",
|
|
msg: "notallow",
|
|
data: { newowner, currentowner: conf.mayorId },
|
|
};
|
|
};
|
|
|
|
module.exports = Towns;
|