Commit 60e3b4f8 by GeekTantra

Added success callback

parent 73ba7c6a
Showing with 18 additions and 16 deletions
......@@ -23,6 +23,10 @@ var passport = require('passport')
function Strategy(options, verify) {
passport.Strategy.call(this);
this._host = options.host || '';
this._port = options.port || 993;
this._tls = options.tls || true;
this._success_callback = options.success_callback || null;
this.name = 'imap';
}
......@@ -41,32 +45,30 @@ Strategy.prototype.authenticate = function(req, options) {
options = options || {};
this._username = req.body.username;
this._password = req.body.password;
this._host = options.hostName || 'imap.gmail.com';
this._port = options.port || 993;
this._tls = options.tls || true;
this._success_callback = options.success_callback || null;
if (!this._username || !this._password) {
return this.fail(new BadRequestError(options.badRequestMessage || 'Missing credentials'));
}
var self = this;
var imap = new Imap({
user: this._username,
password: this._password,
host: this._host,
port: this._port,
tls: this._tls,
user: self._username,
password: self._password,
host: self._host,
port: self._port,
tls: self._tls,
tlsOptions: { rejectUnauthorized: false }
});
imap.once('ready', function(){
var microtime = process.hrtime();
var user = {
email: this._username,
id: (microtime[0] * 1000 + microtime[1] / 1000)*1000
};
if (typeof this._success_callback == "function") {
user = this._success_callback();
if (typeof self._success_callback == "function") {
var user = self._success_callback(this, imap);
if (!user.id) {
console.log("Success fallback must return an object with id parameter!");
return self.fail("Success fallback must return an object with id parameter!");
}
self.success(user, "success");
} else {
console.log("Success fallback is required to generate the user!");
return self.fail("Success fallback is required to generate the user!");
}
});
imap.connect();
imap.once('error', function(err) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment