wildduck/lib/handlers/on-auth.js

37 lines
909 B
JavaScript
Raw Normal View History

'use strict';
module.exports = (server, userHandler) => (login, session, callback) => {
let username = (login.username || '').toString().trim();
userHandler.authenticate(
username,
login.password,
2017-07-24 21:44:08 +08:00
'imap',
{
protocol: 'IMAP',
2017-10-30 19:41:53 +08:00
sess: session.id,
ip: session.remoteAddress
},
(err, result) => {
if (err) {
return callback(err);
}
if (!result) {
return callback();
}
2017-07-24 21:44:08 +08:00
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
}
});
}
);
};