check if the new address is not already used

This commit is contained in:
Andris Reinman 2016-12-07 16:21:22 +02:00
parent 7fce6e28fa
commit 57c6e0ae79

View file

@ -1167,25 +1167,42 @@ module.exports.updateAddress = (list, cid, updates, optInIp, callback) => {
let query = 'SELECT `id`, `email` FROM `subscription__' + list.id + '` WHERE `cid`=? LIMIT 1';
let args = [cid];
connection.query(query, args, (err, rows) => {
connection.release();
if (err) {
connection.release();
return callback(err);
}
if (!rows || !rows.length) {
connection.release();
return callback(new Error('Unknown subscription ID'));
}
if (rows[0].email === emailNew) {
connection.release();
return callback(new Error('Nothing seems to be changed'));
}
let old = rows[0];
let query = 'SELECT `id` FROM `subscription__' + list.id + '` WHERE `email`=? AND `cid`<>? LIMIT 1';
let args = [emailNew, cid];
connection.query(query, args, (err, rows) => {
connection.release();
if (err) {
return callback(err);
}
if (rows && rows[0] && rows[0].id) {
return callback(new Error('This address is already registered by someone else'));
}
module.exports.addConfirmation(list, emailNew, optInIp, {
action: 'update',
cid,
subscriber: rows[0].id,
emailOld: rows[0].email
subscriber: old.id,
emailOld: old.email
}, callback);
});
});
});
});
};