mirror of
https://github.com/nodemailer/wildduck.git
synced 2024-11-11 01:54:04 +08:00
34 lines
863 B
JavaScript
34 lines
863 B
JavaScript
'use strict';
|
|
|
|
module.exports = (server, userHandler) => (login, session, callback) => {
|
|
let username = (login.username || '').toString().trim();
|
|
|
|
userHandler.authenticate(
|
|
username,
|
|
login.password,
|
|
{
|
|
protocol: 'IMAP',
|
|
ip: session.remoteAddress
|
|
},
|
|
(err, result) => {
|
|
if (err) {
|
|
return callback(err);
|
|
}
|
|
if (!result) {
|
|
return callback();
|
|
}
|
|
|
|
if (result.scope === 'master' && result.enabled2fa) {
|
|
// master password not allowed if 2fa is enabled!
|
|
return callback();
|
|
}
|
|
|
|
callback(null, {
|
|
user: {
|
|
id: result.user,
|
|
username: result.username
|
|
}
|
|
});
|
|
}
|
|
);
|
|
};
|