diff --git a/lib/db/json.js b/lib/db/json.js index 376a2a791cae9a968949a202772df5c2193d552f..34cb13b3e0a9f7e43a110b7ebc34f36fb9cd0193 100644 --- a/lib/db/json.js +++ b/lib/db/json.js @@ -168,7 +168,7 @@ function addEmailToAccount(userID, email, type, cb) { sync(); var emails = jsel.match(":has(.id:expr(x="+ ESC(userID) +")) > .emails", db.users); if (emails && emails.length > 0) { - emails[0][email] = { type: type }; + emails[0][email] = { type: type, verified: true }; flush(); } cb(null); @@ -211,7 +211,7 @@ exports.stageEmail = function(existing_user, new_email, hash, cb) { exports.createUserWithPrimaryEmail = function(email, cb) { var emailVal = { }; - emailVal[email] = { type: 'primary' }; + emailVal[email] = { type: 'primary', verified: true }; var uid = getNextUserID(); db.users.push({ id: uid, @@ -276,7 +276,7 @@ exports.gotVerificationSecret = function(secret, cb) { exports.emailKnown(o.email, function(err, known) { function createAccount() { var emailVal = {}; - emailVal[o.email] = { type: 'secondary' }; + emailVal[o.email] = { type: 'secondary', verified: true }; var uid = getNextUserID(); var hash = o.passwd; db.users.push({ @@ -435,7 +435,7 @@ exports.addTestUser = function(email, hash, cb) { sync(); removeEmailNoCheck(email, function() { var emailVal = {}; - emailVal[email] = { type: 'secondary' }; + emailVal[email] = { type: 'secondary', verified: true }; db.users.push({ id: getNextUserID(), password: hash, diff --git a/lib/db/mysql.js b/lib/db/mysql.js index f9d37b753a33d1c05ca30d775060a8201156e550..b1461c3042cccdc0190e130bb92625a7c13bfa02 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -72,6 +72,7 @@ const schemas = [ "user BIGINT NOT NULL," + "address VARCHAR(255) UNIQUE NOT NULL," + "type ENUM('secondary', 'primary') DEFAULT 'secondary' NOT NULL," + + "verified BOOLEAN DEFAULT TRUE NOT NULL, " + "FOREIGN KEY user_fkey (user) REFERENCES user(id)" + ") ENGINE=InnoDB;", @@ -331,7 +332,6 @@ function addEmailToUser(userID, email, type, cb) { }); } - exports.gotVerificationSecret = function(secret, cb) { client.query( "SELECT * FROM staged WHERE secret = ?", [ secret ], @@ -471,18 +471,20 @@ exports.updatePassword = function(uid, hash, cb) { */ exports.listEmails = function(uid, cb) { client.query( - 'SELECT address, type FROM email WHERE user = ?', + 'SELECT address, type, verified FROM email WHERE user = ?', [ uid ], function (err, rows) { if (err) cb(err); else { var emails = {}; - // eventually we'll have fields in here - for (var i = 0; i < rows.length; i++) - emails[rows[i].address] = { - type: rows[i].type - }; + for (var i = 0; i < rows.length; i++) { + var o = { type: rows[i].type }; + if (o.type === 'secondary') { + o.verified = rows[i].verified; + } + emails[rows[i].address] = o; + } cb(null,emails); } diff --git a/tests/list-emails-wsapi-test.js b/tests/list-emails-wsapi-test.js index 037bed0b812225b6618a231c75f94ec25e12bf33..0eb3449b7461b485b3ddb31f1cd1e5a7898d272b 100755 --- a/tests/list-emails-wsapi-test.js +++ b/tests/list-emails-wsapi-test.js @@ -85,6 +85,7 @@ suite.addBatch({ var emails = Object.keys(respObj); assert.equal(emails[0], "syncer@somehost.com"); assert.equal(respObj[emails[0]].type, "secondary"); + assert.equal(respObj[emails[0]].verified, true); assert.equal(emails.length, 1); } }