This commit is contained in:
AJ ONeal 2018-08-04 10:36:27 +00:00
parent a2b23b2509
commit 4f2948d0f0
1 changed files with 8 additions and 5 deletions

View File

@ -188,13 +188,13 @@ DB.ports._add = function (acc, number) {
});
};
DB._save = function () {
return sfs.writeAsync('./accounts.json', JSON.stringify(DB._perms));
return sfs.writeFileAsync('./accounts.json', JSON.stringify(DB._perms));
};
DB._saveToken = null;
DB._savePromises = [];
DB._savePromise = PromiseA.resolve();
DB.save = function () {
cancelTimeout(DB._saveToken);
clearTimeout(DB._saveToken);
return new Promise(function (resolve, reject) {
function doSave() {
DB._savePromise = DB._savePromise.then(function () {
@ -214,7 +214,7 @@ DB.save = function () {
}
DB._saveToken = setTimeout(doSave, 2500);
DB.savePromises.push({ resolve: resolve, reject: reject });
DB._savePromises.push({ resolve: resolve, reject: reject });
});
};
@ -917,7 +917,7 @@ Accounts._associateEmails = function (req) {
// oauth3.org, issuer@oauth3.org, profile
return OAUTH3.request({
url: "https://api." + req.auth.data.iss + "/api/issuer@oauth3.org/acl/profile"
, session: { accessToken: req.auth.jwt }
, session: { accessToken: req.auth.jwt, token: req.auth.data }
}).then(function (resp) {
var email;
var err;
@ -940,7 +940,7 @@ Accounts._associateEmails = function (req) {
};
app.get('/api/telebit.cloud/account', function (req, res) {
return Accounts.getOrCreate(req).then(function (acc) {
var hasEmail = subData.nodes.some(function (node) {
var hasEmail = acc.nodes.some(function (node) {
return 'email' === node.type;
});
function getAllGrants() {
@ -953,6 +953,8 @@ app.get('/api/telebit.cloud/account', function (req, res) {
result.domains.length = 0;
result.ports.length = 0;
grants.forEach(function (account) {
if (!account) { return; }
console.log('grants.forEach.account: ', account);
account.domains.forEach(function (d) {
domainsMap[d.name] = d;
});
@ -986,6 +988,7 @@ app.get('/api/telebit.cloud/account', function (req, res) {
error: {
code: err.code || "E_GENERIC"
, message: err.toString()
, _stack: err.stack
}
});
});