obvious bugfixes
This commit is contained in:
parent
5b7f19e7a8
commit
60ee3720e0
|
@ -15,7 +15,7 @@ var crypto = require('crypto');
|
|||
var escapeHtml = require('escape-html');
|
||||
var jwt = require('jsonwebtoken');
|
||||
var requestAsync = util.promisify(require('@coolaj86/urequest'));
|
||||
var readFileAsync = util.promisify(fs.readFile);
|
||||
//var readFileAsync = util.promisify(fs.readFile);
|
||||
var mkdirpAsync = util.promisify(require('mkdirp'));
|
||||
var TRUSTED_ISSUERS = [ 'oauth3.org' ];
|
||||
var DB = {};
|
||||
|
@ -46,14 +46,14 @@ DB._load = function () {
|
|||
DB._grants[acc.id] = [];
|
||||
}
|
||||
acc.domains.forEach(function (d) {
|
||||
DB._grants[d.name + '|id|' + acc.id] = true
|
||||
DB._grants[d.name + '|id|' + acc.id] = true;
|
||||
if (!DB._grantsMap[acc.id][d.name]) {
|
||||
DB._grantsMap[acc.id][d.name] = d;
|
||||
DB._grants[acc.id].push(d);
|
||||
}
|
||||
});
|
||||
acc.ports.forEach(function (p) {
|
||||
DB._grants[p.number + '|id|' + acc.id] = true
|
||||
DB._grants[p.number + '|id|' + acc.id] = true;
|
||||
if (!DB._grantsMap[acc.id][p.number]) {
|
||||
DB._grantsMap[acc.id][p.number] = p;
|
||||
DB._grants[acc.id].push(p);
|
||||
|
@ -78,14 +78,14 @@ DB._load = function () {
|
|||
DB._grants[node.name] = [];
|
||||
}
|
||||
acc.domains.forEach(function (d) {
|
||||
DB._grants[d.name + '|' + (node.scheme||node.type) + '|' + node.name] = true
|
||||
DB._grants[d.name + '|' + (node.scheme||node.type) + '|' + node.name] = true;
|
||||
if (!DB._grantsMap[node.name][d.name]) {
|
||||
DB._grantsMap[node.name][d.name] = d;
|
||||
DB._grants[node.name].push(d);
|
||||
}
|
||||
});
|
||||
acc.ports.forEach(function (p) {
|
||||
DB._grants[p.number + '|' + (node.scheme||node.type) + '|' + node.name] = true
|
||||
DB._grants[p.number + '|' + (node.scheme||node.type) + '|' + node.name] = true;
|
||||
if (!DB._grantsMap[node.name][p.number]) {
|
||||
DB._grantsMap[node.name][p.number] = p;
|
||||
DB._grants[node.name].push(p);
|
||||
|
@ -107,7 +107,7 @@ DB._load = function () {
|
|||
});
|
||||
acc.ports.forEach(function (port) {
|
||||
if (DB._byPort[port.number]) {
|
||||
console.warn("duplicate port '" + domain.number + "'");
|
||||
console.warn("duplicate port '" + port.number + "'");
|
||||
console.warn("::existing account '" + acc.nodes.map(function (node) { return node.name; }) + "'");
|
||||
console.warn("::new account '" + DB._byPort[port.number].account.nodes.map(function (node) { return node.name; }) + "'");
|
||||
}
|
||||
|
@ -156,7 +156,7 @@ DB.domains._add = function (acc, opts) {
|
|||
, wildcard: opts.wildcard
|
||||
};
|
||||
var pdomain;
|
||||
var parts = name.split('.').map(function (el, i) {
|
||||
var parts = name.split('.').map(function (el, i, arr) {
|
||||
return arr.slice(i).join('.');
|
||||
}).reverse();
|
||||
parts.shift();
|
||||
|
@ -200,15 +200,15 @@ DB.ports._add = function (acc, opts) {
|
|||
, os: opts.os
|
||||
, createdAt: new Date().toISOString()
|
||||
};
|
||||
if (DB._byPort[number]) {
|
||||
if (DB._byPort[port.number]) {
|
||||
// TODO verifications
|
||||
throw new Error("port '" + number + "' exists");
|
||||
throw new Error("port '" + port.number + "' exists");
|
||||
}
|
||||
DB._byPort[number] = {
|
||||
DB._byPort[port.number] = {
|
||||
account: acc
|
||||
, domain: domain
|
||||
, port: port
|
||||
};
|
||||
acc.domains.push(domain);
|
||||
acc.ports.push(port);
|
||||
});
|
||||
};
|
||||
DB._save = function () {
|
||||
|
@ -219,7 +219,7 @@ DB._savePromises = [];
|
|||
DB._savePromise = PromiseA.resolve();
|
||||
DB.save = function () {
|
||||
clearTimeout(DB._saveToken);
|
||||
return new Promise(function (resolve, reject) {
|
||||
return new PromiseA(function (resolve, reject) {
|
||||
function doSave() {
|
||||
DB._savePromise = DB._savePromise.then(function () {
|
||||
return DB._save().then(function (yep) {
|
||||
|
@ -709,11 +709,11 @@ DB.getDomainAndPort = function (state) {
|
|||
portCount += 1;
|
||||
var portnumber = (1024 + 1) + Math.round(Math.random() * 65535);
|
||||
return DB.ports.available(portnumber).then(function (available) {
|
||||
if (!available) { return portDomain(); }
|
||||
if (!available) { return choosePort(); }
|
||||
return portnumber;
|
||||
});
|
||||
}
|
||||
return Promise.all([
|
||||
return PromiseA.all([
|
||||
chooseDomain()
|
||||
, choosePort()
|
||||
]).then(function (two) {
|
||||
|
@ -745,8 +745,7 @@ module.exports.pairPin = function (opts) {
|
|||
}
|
||||
|
||||
console.log('[pairPin] generating offer');
|
||||
return DB.getDomainAndPort(state);
|
||||
}).then(function (grantable) {
|
||||
return DB.getDomainAndPort(state).then(function (grantable) {
|
||||
var emailNode = { scheme: 'mailto', type: 'email', name: auth.subject };
|
||||
|
||||
return DB.accounts.get(emailNode).then(function (_acc) {
|
||||
|
@ -805,6 +804,7 @@ module.exports.pairPin = function (opts) {
|
|||
});
|
||||
*/
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
// From a WS connection
|
||||
|
@ -952,9 +952,9 @@ Accounts._associateEmails = function (req) {
|
|||
}).then(function (resp) {
|
||||
var email;
|
||||
var err;
|
||||
(resp.data.nodes||[]).some(function (node) {
|
||||
(resp.data.nodes||[]).some(function (/*node*/) {
|
||||
// TODO use verified email addresses
|
||||
return true
|
||||
return true;
|
||||
});
|
||||
// back-compat for current way email is stored
|
||||
if (!email && /@/.test(resp.data.username)) {
|
||||
|
@ -962,7 +962,7 @@ Accounts._associateEmails = function (req) {
|
|||
}
|
||||
if (!email) {
|
||||
err = new Error ("could not find a verified email address in profile settings");
|
||||
err.code = "E_NO_EMAIL"
|
||||
err.code = "E_NO_EMAIL";
|
||||
return PromiseA.reject(err);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue