Add ability to update email address

This implementation is not going to scale well :/
This commit is contained in:
Aron Carroll 2012-06-22 15:27:25 +01:00
parent 8c73544225
commit 684bdba638
3 changed files with 16 additions and 6 deletions

View File

@ -154,8 +154,8 @@ MySQL.prototype = {
},
getUser: function (id, fn) {
this.connection.query(templates.getUser, [id], function (err, results) {
if (err || !results.length) {
return fn(!err && !results.length ? 'not-found' : err);
if (err) {
return fn(err);
}
fn(null, results[0]);
});
@ -194,12 +194,20 @@ MySQL.prototype = {
fn(null, results.insertId);
});
},
updateUserEmail: function (id, email, fn) {
this.connection.query(templates.updateUserEmail, [email, id], function (err, results) {
if (err) {
return fn(err);
}
fn(null);
});
},
updateUserKey: function (id, key, fn) {
this.connection.query(templates.updateUserKey, [key, id], function (err, results) {
if (err || !results.affectedRows) {
return fn(!err && !results.length ? 'not-found' : err);
if (err) {
return fn(err);
}
fn(null, results.insertId);
fn(null);
});
},
getUserByForgotToken: function (token, fn) {

View File

@ -8,7 +8,8 @@
"getUserByEmail": "SELECT * FROM `ownership` WHERE `email`=? LIMIT 1",
"setUser": "INSERT INTO `ownership` (`name`, `key`, `email`, `last_login`, `created`, `updated`) VALUES (?, ?, ?, NOW(), NOW(), NOW())",
"touchLogin": "UPDATE `ownership` SET `last_login`=NOW() WHERE `name`=?",
"updateUserKey": "UPDATE ownership SET `key`=?, `created`=NOW(), `updated`=NOW() WHERE `name`=?",
"updateUserEmail": "UPDATE ownership SET `email`=?, `updated`=NOW() WHERE `name`=?",
"updateUserKey": "UPDATE ownership SET `key`=?, `updated`=NOW() WHERE `name`=?",
"setBinForUser": "INSERT INTO `owners` (`name`, `url`, `revision`) VALUES (?, ?, ?)",
"getBinsByUser": "SELECT `url`, `revision` FROM `owners` WHERE `name`=? ORDER BY `url`, `revision` DESC",
"getBinByUrlAndRevision": "SELECT * FROM `sandbox` WHERE `url`=? AND `revision`=? LIMIT 1",

View File

@ -18,6 +18,7 @@ var methods = [
'getUserByEmail',
'setUser',
'touchLogin',
'updateUserEmail',
'updateUserKey',
'getUserByForgotToken',
'setForgotToken',