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,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 query = 'SELECT `id`, `email` FROM `subscription__' + list.id + '` WHERE `cid`=? LIMIT 1';
|
||||||
let args = [cid];
|
let args = [cid];
|
||||||
connection.query(query, args, (err, rows) => {
|
connection.query(query, args, (err, rows) => {
|
||||||
connection.release();
|
|
||||||
if (err) {
|
if (err) {
|
||||||
|
connection.release();
|
||||||
return callback(err);
|
return callback(err);
|
||||||
}
|
}
|
||||||
if (!rows || !rows.length) {
|
if (!rows || !rows.length) {
|
||||||
|
connection.release();
|
||||||
return callback(new Error('Unknown subscription ID'));
|
return callback(new Error('Unknown subscription ID'));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rows[0].email === emailNew) {
|
if (rows[0].email === emailNew) {
|
||||||
|
connection.release();
|
||||||
return callback(new Error('Nothing seems to be changed'));
|
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, {
|
module.exports.addConfirmation(list, emailNew, optInIp, {
|
||||||
action: 'update',
|
action: 'update',
|
||||||
cid,
|
cid,
|
||||||
subscriber: rows[0].id,
|
subscriber: old.id,
|
||||||
emailOld: rows[0].email
|
emailOld: old.email
|
||||||
}, callback);
|
}, callback);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
});
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue