mirror of
https://github.com/nodemailer/wildduck.git
synced 2025-01-08 17:07:44 +08:00
35 lines
863 B
JavaScript
35 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
|
||
|
}
|
||
|
});
|
||
|
}
|
||
|
);
|
||
|
};
|