2017-07-16 00:08:33 +08:00
|
|
|
'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',
|
2017-07-16 00:08:33 +08:00
|
|
|
{
|
|
|
|
protocol: 'IMAP',
|
2017-10-30 19:41:53 +08:00
|
|
|
sess: session.id,
|
2017-07-16 00:08:33 +08:00
|
|
|
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) {
|
2017-07-16 00:08:33 +08:00
|
|
|
// master password not allowed if 2fa is enabled!
|
|
|
|
return callback();
|
|
|
|
}
|
|
|
|
|
|
|
|
callback(null, {
|
|
|
|
user: {
|
|
|
|
id: result.user,
|
|
|
|
username: result.username
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
};
|