mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-10-06 11:57:27 +08:00
v1.0.75
This commit is contained in:
parent
ea67b25bb5
commit
5862950741
2 changed files with 82 additions and 4 deletions
|
@ -27,6 +27,75 @@ class UserHandler {
|
||||||
this.authlogExpireDays = options.authlogExpireDays;
|
this.authlogExpireDays = options.authlogExpireDays;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reolve user by username/address
|
||||||
|
*
|
||||||
|
* @param {String} username Either username or email address
|
||||||
|
* @param {Object} [extraFields] Optional projection fields object
|
||||||
|
*/
|
||||||
|
get(username, extraFields, callback) {
|
||||||
|
if (!callback && typeof extraFields === 'function') {
|
||||||
|
callback = extraFields;
|
||||||
|
extraFields = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
let fields = {
|
||||||
|
_id: true,
|
||||||
|
quota: true,
|
||||||
|
storageUsed: true,
|
||||||
|
disabled: true
|
||||||
|
};
|
||||||
|
|
||||||
|
Object.keys(extraFields || {}).forEach(field => {
|
||||||
|
fields[field] = true;
|
||||||
|
});
|
||||||
|
|
||||||
|
let checkAddress = next => {
|
||||||
|
if (username.indexOf('@') < 0) {
|
||||||
|
// assume regular username
|
||||||
|
return next(null, {
|
||||||
|
unameview: username.replace(/\./g, '')
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// try to find existing email address
|
||||||
|
let address = tools.normalizeAddress(username);
|
||||||
|
this.users.collection('addresses').findOne({
|
||||||
|
addrview: address.substr(0, address.indexOf('@')).replace(/\./g, '') + address.substr(address.indexOf('@'))
|
||||||
|
}, {
|
||||||
|
fields: {
|
||||||
|
user: true
|
||||||
|
}
|
||||||
|
}, (err, addressData) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!addressData) {
|
||||||
|
return callback(null, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
next(null, { _id: addressData.user });
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
checkAddress((err, query) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.users.collection('users').findOne(query, {
|
||||||
|
fields
|
||||||
|
}, (err, userData) => {
|
||||||
|
if (err) {
|
||||||
|
return callback(err);
|
||||||
|
}
|
||||||
|
|
||||||
|
return callback(null, userData);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Authenticate user
|
* Authenticate user
|
||||||
*
|
*
|
||||||
|
@ -182,7 +251,10 @@ class UserHandler {
|
||||||
return this.logAuthEvent(userData._id, meta, () => authFail(null, false));
|
return this.logAuthEvent(userData._id, meta, () => authFail(null, false));
|
||||||
}
|
}
|
||||||
|
|
||||||
let prefix = crypto.createHash('md5').update(password.substr(0, 4)).digest('hex');
|
let prefix = crypto
|
||||||
|
.createHash('md5')
|
||||||
|
.update(password.substr(0, 4))
|
||||||
|
.digest('hex');
|
||||||
|
|
||||||
this.users
|
this.users
|
||||||
.collection('asps')
|
.collection('asps')
|
||||||
|
@ -270,7 +342,10 @@ class UserHandler {
|
||||||
// We need a quick hash key that can be used to identify the password.
|
// We need a quick hash key that can be used to identify the password.
|
||||||
// Otherwise, when authenticating, we'd need to check the password against all stored bcrypt
|
// Otherwise, when authenticating, we'd need to check the password against all stored bcrypt
|
||||||
// hashes which would make forever if the user has a longer list of application specific passwords
|
// hashes which would make forever if the user has a longer list of application specific passwords
|
||||||
let prefix = crypto.createHash('md5').update(password.substr(0, 4)).digest('hex');
|
let prefix = crypto
|
||||||
|
.createHash('md5')
|
||||||
|
.update(password.substr(0, 4))
|
||||||
|
.digest('hex');
|
||||||
|
|
||||||
let allowedScopes = ['imap', 'pop3', 'smtp'];
|
let allowedScopes = ['imap', 'pop3', 'smtp'];
|
||||||
let hasAllScopes = false;
|
let hasAllScopes = false;
|
||||||
|
@ -1090,7 +1165,10 @@ class UserHandler {
|
||||||
}
|
}
|
||||||
|
|
||||||
entry.count = 1;
|
entry.count = 1;
|
||||||
entry.groupKey = crypto.createHash('sha1').update(entry.groupKey + ':' + Math.floor(Date.now() / (3600 * 1000))).digest('base64');
|
entry.groupKey = crypto
|
||||||
|
.createHash('sha1')
|
||||||
|
.update(entry.groupKey + ':' + Math.floor(Date.now() / (3600 * 1000)))
|
||||||
|
.digest('base64');
|
||||||
entry.updated = entry.created;
|
entry.updated = entry.created;
|
||||||
this.users.collection('authlog').findOneAndUpdate({
|
this.users.collection('authlog').findOneAndUpdate({
|
||||||
user,
|
user,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "wildduck",
|
"name": "wildduck",
|
||||||
"version": "1.0.74",
|
"version": "1.0.75",
|
||||||
"description": "IMAP server built with Node.js and MongoDB",
|
"description": "IMAP server built with Node.js and MongoDB",
|
||||||
"main": "server.js",
|
"main": "server.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
Loading…
Add table
Reference in a new issue