forked from dgaiero/cpieee-member-services
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
93 lines (84 loc) · 3.12 KB
/
server.js
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
var express = require('express');
var app = express();
var bodyParser = require('body-parser');
var session = require('express-session');
var ActiveDirectory = require('activedirectory');
var path = require('path');
var soap = require('soap');
var multer = require('multer');
var _ = require('underscore');
var fs = require('fs');
var upload = multer({dest: path.join(__dirname,'../uploads')});
var docxConverter = require('docx-pdf');
var usersarray;
var replaceExt = require('replace-ext');
var ldap = require('ldapjs');
app.use(express.static(__dirname + '/dist'));
app.use(bodyParser.json());
app.use(session({
secret: 'keyboard cat',
resave: false,
saveUninitialized: true,
cookie: { secure: false }
}))
app.get('*', function (req, res) {
console.log('I received a GET request');
res.sendFile(path.join(__dirname, '/dist/index.html'));
});
app.post('/queryUser', function(req, res) {
var config = {
url: 'ldap://ldap.calpolyieee.com:389',
baseDN: 'DC=calpolyieee,DC=com',
username: 'CN=admin,DC=calpolyieee,DC=com',
password: 'p@ssw0rd1999'
}
var ad = new ActiveDirectory(config);
var users;
var opts = {includeMembership: ['all'],
attributes: ['cn', 'displayName', 'ieeeExpiration', 'ieeeMemberNumber', 'mail', 'member', 'o', 'sn', 'uid', 'description'],
baseDn: 'dc=members,dc=calpolyieee,dc=com',
filter: '(\|(member=cn=activeMembers,dc=calpolyieee,dc=com)(member=cn=inactiveMembers,dc=calpolyieee,dc=com)(member=cn=arrearsMembers,dc=calpolyieee,dc=com))'};
ad.find(opts, function(err, results) {
var users=[];
_.each(results.other, function(other) {
users.push(other);
});
res.json({users: users});
});
});
app.post('/authenticate', function(req, res) {
var config = {
url: 'ldap://ldap.calpolyieee.com:389',
baseDN: 'DC=calpolyieee,DC=com',
username: 'CN=admin,DC=calpolyieee,DC=com',
password: 'p@ssw0rd1999'
}
var opts = {includeMembership: ['all'],
attributes: ['cn', 'displayName', 'ieeeExpiration', 'ieeeMemberNumber', 'mail', 'member', 'o', 'sn', 'uid', 'description', 'userPassword'],
filter: '(&(objectClass=ieeeUser)(member=cn=officers,dc=calpolyieee,dc=com))',
baseDn: 'dc=members,dc=calpolyieee,dc=com'};
var ad = new ActiveDirectory(config);
var username = 'ieeeMemberNumber=' + req.body['username'] + ',dc=members,dc=calpolyieee,dc=com';
var password = req.body['password'];
ad.authenticate(username, password, function(err, auth) {
if (auth) {
req.session.isAuthenticated = true;
res.json({isAuthenticated: req.session.isAuthenticated});
}
else {
req.session.isAuthenticated = false;
res.json({isAuthenticated: req.session.isAuthenticated});
}
});
});
app.post('/logout', function(req, res) {
//getApprovers("RevisedDeviation","DEV-003952M","CCB");
req.session.isAuthenticated = false;
res.json({isAuthenticated :req.session.isAuthenticated, loggedInUsername :req.session.loggedInUserGivenName});
});
app.post('/isAuthenticated', function(req, res) {
console.log(req.session);
res.json({isAuthenticated: req.session.isAuthenticated});
})
app.listen(3000);
console.log("Server running on port 3000");