Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Carlos
/
passport-imap
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
60e3b4f8
authored
Sep 13, 2013
by
GeekTantra
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added success callback
parent
73ba7c6a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
17 deletions
lib/passport-imap/strategy.js
lib/passport-imap/strategy.js
View file @
60e3b4f8
...
...
@@ -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!"
);
}
self
.
success
(
user
,
"success"
);
});
imap
.
connect
();
imap
.
once
(
'error'
,
function
(
err
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment