diff --git a/lib/db/mysql.js b/lib/db/mysql.js index 5e5dcf98eb4b624678322afe74ab29a0a645bcba..b2e123ae6667e7c150963f627f0af30ba9c491bc 100644 --- a/lib/db/mysql.js +++ b/lib/db/mysql.js @@ -355,32 +355,26 @@ exports.gotVerificationSecret = function(secret, cb) { addEmailToUser(info.insertId, o.email, 'secondary', cb); }); } else { - // we need a userid. the old schema had an 'existing' field which was an email - // address. the new schema has an 'existing_user' field which is a userid. - // this is transitional code so outstanding verification links continue working - // and can be removed in feb 2012 some time. maybe for valentines day? - if (typeof o.existing_user === 'number') doAddEmailSetPassword(o.existing_user); - else if (typeof o.existing === 'string') { - exports.emailToUID(o.existing, function(uid) { - if (err || uid === undefined) return cb('acct associated with staged email doesn\'t exist'); - doAddEmailSetPassword(uid); - }); + // ensure the expected existing_user field is populated, which it must always be when + // new_acct is false + if (typeof o.existing_user !== 'number') { + return cb("data inconsistency, no numeric existing user associated with staged email address"); } - function doAddEmailSetPassword(uid) { - // we're adding an email address to an existing user account. add appropriate entries into - // email table - var hash = o.passwd; - if (hash) { - exports.updatePassword(uid, hash, function(err) { - if (err) return cb('could not set user\'s password'); - addEmailToUser(uid, o.email, 'secondary', cb); - }); - } else { + + // we're adding an email address to an existing user account. add appropriate entries into + // email table + var hash = o.passwd; + var uid = o.existing_user; + if (hash) { + exports.updatePassword(uid, hash, function(err) { + if (err) return cb('could not set user\'s password'); addEmailToUser(uid, o.email, 'secondary', cb); - } + }); + } else { + addEmailToUser(uid, o.email, 'secondary', cb); } - }; - } + } + }; } ); }