Skip to content
Snippets Groups Projects
Commit 9eb3ff35 authored by Lloyd Hilaiel's avatar Lloyd Hilaiel
Browse files

incremental development on pure json database

parent 499628d3
No related branches found
No related tags found
No related merge requests found
......@@ -67,6 +67,8 @@ exports.addKeyToEmail = function(existing_email, email, pubkey, cb) {
return;
}
if (db[userID].emails
db.execute("SELECT emails.id FROM emails,users WHERE users.id = ? AND emails.address = ? AND emails.user = users.id",
[ userID, email ],
function(err, rows) {
......@@ -124,16 +126,19 @@ exports.gotVerificationSecret = function(secret, cb) {
if (o.type === 'add_account') {
exports.emailKnown(o.email, function(known) {
function createAccount() {
executeTransaction([
[ "INSERT INTO users (password) VALUES(?)", [ o.pass ] ] ,
[ "INSERT INTO emails (user, address) VALUES(last_insert_rowid(),?)", [ o.email ] ],
[ "INSERT INTO keys (email, key, expires) VALUES(last_insert_rowid(),?,?)",
[ o.pubkey, ((new Date()).getTime() + (14 * 24 * 60 * 60 * 1000)) ]
db.push({
password: o.pass,
emails: [
{
address: o.email,
keys: [ {
key: o.pubkey,
expires: ((new Date()).getTime() + (14 * 24 * 60 * 60 * 1000))
} ]
}
]
], function (error) {
if (error) cb(error);
else cb();
});
cb();
}
// if this email address is known and a user has completed a re-verification of this email
......@@ -142,6 +147,7 @@ exports.gotVerificationSecret = function(secret, cb) {
// NOTE: this might be sub-optimal, but it's a dead simple approach that mitigates many attacks
// and gives us reasonable behavior (without explicitly supporting) in the face of shared email
// addresses.
if (known) {
exports.removeEmail(o.email, o.email, function (err) {
if (err) cb(err);
......@@ -178,6 +184,22 @@ exports.checkAuth = function(email, cb) {
});
};
function emailToUserID(email, cb) {
var id = undefined;
for (var i = 0; i < db.length; i++) {
for (var j = 0; j < db[i].emails.length; j++) {
if (db[i].emails[j].address === email) {
id = i;
break;
}
}
if (id !== undefined) break;
}
setTimeout(function() { cb(id); }, 0);
}
exports.getSyncResponse = function(email, identities, cb) {
var respBody = {
unknown_emails: [ ],
......
......@@ -25,7 +25,7 @@ suite.addBatch({
},
"opening the database": {
topic: function() {
db.open({ /* driver: 'json', */ path: dbPath }, this.callback);
db.open({ driver: 'json', path: dbPath }, this.callback);
},
"and its ready": function(r) {
assert.isUndefined(r);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment