check if the new address is not already used
This commit is contained in:
parent
7fce6e28fa
commit
57c6e0ae79
1 changed files with 24 additions and 7 deletions
|
@ -1167,24 +1167,41 @@ 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'));
|
||||
}
|
||||
|
||||
module.exports.addConfirmation(list, emailNew, optInIp, {
|
||||
action: 'update',
|
||||
cid,
|
||||
subscriber: rows[0].id,
|
||||
emailOld: rows[0].email
|
||||
}, callback);
|
||||
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: old.id,
|
||||
emailOld: old.email
|
||||
}, callback);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue