Sun Jan 29 2017
Copied to clipboard! Copy reply
  • 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
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
import 'babel-polyfill'
import os from 'os'
import path from 'path'
import fs from 'fs-extra'
import exec from 'child_process'
import Koa from 'koa'
import cors from 'kcors'
import Router from 'koa-router'
import koaBody from 'koa-body'
import convert from 'koa-convert'
import session from "koa-session2"
import websockify from 'koa-websocket'
import * as route from './routes'
import cfg from './config'
import Store from './memstore'

const serve = require('koa-static')
//const app = websockify(new Koa())
const router = new Router()
const koabody = new koaBody({
  multipart: true,
  formidable: {uploadDir: os.tmpdir()}
})


import ldap from 'ldapjs'



const app = new Koa();

app.use(session({key:'SESSION', store: new Store()}))




class Auth
{

  static login(ctx, next)
  {

    var Login = function() {
      return new Promise( (resolve, reject) => {

        var client = ldap.createClient({ url: cfg.ldapServer })

        setTimeout(function() {
          resolve()
          console.log('resolved')
        },2000)

      })
    }

    var login =  Login()

    login.then(() => {
      console.log('resolved..')
      ctx.body = 'logged in'
    })

    .catch(() => {
      console.log('rejected')
    })



  }

}




router.get('/login', Auth.login)
router.get('/check', check)

app
  .use(router.allowedMethods())
  .use(router.routes())



function home(ctx, next) {
  var cookie = ctx.cookies.get('color')
  //console.log('Inside /home handler. Cookie: ', cookie)
  next()
}

function check(ctx, next) {
  console.log('session: ', ctx.session.username)
}









app.listen(3000);