- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
static login(ctx, next)
{
const data = {
username: 'jon',
passwd: 'secret'
}
var result = {}
var Login = function() {
return new Promise( (resolve, reject) => {
var client = ldap.createClient({ url: cfg.ldapServer })
client.on('error', err => {
result = {result: 0, payload: 'LDAP server not found'}
reject()
})
client.on('connect', s => {
client.bind( `${server}\\${data.username}`, `${data.passwd}`, err => {
if (err)
{
reject()
result = {result: 0, payload: 'Invalid Credentials.'}
}
else
{
console.log('this gets printed out..')
result = {result: 1, payload: 'success'}
setTimeout(() => { resolve() }, 2000)
}
})
})
})
}
var login = Login()
login.then(() => {
console.log('resolved..')
ctx.session.username = data.username
ctx.body = res
})
.catch(() => {
console.log('rejected')
ctx.body = res
})
}