wildduck/lib/handlers/on-auth.js
2017-07-24 16:44:08 +03:00

35 lines
879 B
JavaScript

'use strict';
module.exports = (server, userHandler) => (login, session, callback) => {
let username = (login.username || '').toString().trim();
userHandler.authenticate(
username,
login.password,
'imap',
{
protocol: 'IMAP',
ip: session.remoteAddress
},
(err, result) => {
if (err) {
return callback(err);
}
if (!result) {
return callback();
}
if (result.scope === 'master' && result.require2fa) {
// master password not allowed if 2fa is enabled!
return callback();
}
callback(null, {
user: {
id: result.user,
username: result.username
}
});
}
);
};