Added a basic user search
This commit is contained in:
@ -1,3 +1,32 @@
|
||||
const ldap = require('ldapjs');
|
||||
|
||||
exports.getLogin = (req, res, next) => {
|
||||
res.render('auth/login');
|
||||
};
|
||||
|
||||
exports.postLogin = (req, res, next) => {
|
||||
|
||||
bindHost = req.body.ldap_bind_host;
|
||||
bindDn = req.body.ldap_bind_dn;
|
||||
bindPw = req.body.ldap_bind_pw;
|
||||
|
||||
client = ldap.createClient({url: 'ldap://' + bindHost + '/'});
|
||||
client.bind(bindDn, bindPw, (err) => {
|
||||
if (err) {
|
||||
console.log('There was an error while logging in. Please try again.');
|
||||
res.redirect('/auth/login');
|
||||
return next(err);
|
||||
} else {
|
||||
console.log('Success!');
|
||||
req.session.ldap_bind_host = bindHost;
|
||||
req.session.ldap_bind_dn = bindDn;
|
||||
req.session.ldap_bind_pw = bindPw;
|
||||
baseDnBits = bindDn.split(',');
|
||||
baseDnBits.shift();
|
||||
baseDn = baseDnBits.join(',');
|
||||
req.session.ldap_base_dn = baseDn;
|
||||
return res.redirect('/');
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
@ -1,3 +1,31 @@
|
||||
exports.home = function(req, res, next) {
|
||||
res.render('index');
|
||||
const ldap = require('ldapjs');
|
||||
|
||||
searchOpts = {
|
||||
filter: '(objectClass=posixAccount)',
|
||||
scope: 'sub',
|
||||
attributes: ['uid', 'displayName', 'mail'],
|
||||
};
|
||||
|
||||
exports.home = function(req, res, next) {
|
||||
|
||||
client = ldap.createClient({url: 'ldap://' + req.session.ldap_bind_host + '/'});
|
||||
client.bind(req.session.ldap_bind_dn, req.session.ldap_bind_pw, (err) => {
|
||||
if (err) {
|
||||
console.log('There was an error while logging in. Please try again.');
|
||||
res.redirect('/auth/login');
|
||||
return next(err);
|
||||
} else {
|
||||
client.search('ou=People,' + req.session.ldap_base_dn, searchOpts, (err, result) => {
|
||||
users = [];
|
||||
result.on('searchEntry', (entry) => {
|
||||
users.push(entry.object);
|
||||
});
|
||||
|
||||
return res.render('index', {
|
||||
users: users
|
||||
});
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
};
|
||||
|
Reference in New Issue
Block a user