wildduck/lib/handlers/on-auth.js
2017-07-15 19:08:33 +03:00

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
}
});
}
);
};