Return members
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Jared He 2021-10-13 01:03:49 -04:00
parent 597f1961c4
commit 615aa3f95f
5 changed files with 79 additions and 9557 deletions

48
lib/ldap.ts Normal file
View File

@ -0,0 +1,48 @@
import { Client } from "ldapts";
interface MemberItem {
name: string;
id: string;
program: string;
}
// note: the term parameter is different due to the way the LDAP database is structured
export async function getMembers(
year: string,
term: "w" | "s" | "f"
): Promise<MemberItem[]> {
let members: MemberItem[] = [];
const url = "ldap://ldap1.csclub.uwaterloo.ca";
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
const client = new Client({
url,
});
try {
await client.bind("", "");
const { searchEntries } = await client.search(searchDN, {
scope: "sub",
filter: `(&(objectClass=member)(term=${term}${year}))`,
});
members = searchEntries
.map((item) => {
return {
name: item.cn as string,
id: item.uid as string,
program: item.program === undefined ? "" : (item.program as string),
};
})
.sort((item1: MemberItem, item2: MemberItem) =>
item1.id.localeCompare(item2.id)
);
}
// catch (ex) {
// throw ex;
// }
finally {
await client.unbind();
}
return members;
}

8
lib/test.ts Normal file
View File

@ -0,0 +1,8 @@
import { getMembers } from "./ldap";
const main = async () => {
const members = await getMembers("2020", "w");
console.log(members);
};
void main();

9531
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,6 @@
"lint": "eslint \"{pages,components,lib,hooks,scripts}/**/*.{js,ts,tsx,jsx}\" --quiet",
"lint:fix": "eslint \"{pages,components,lib,hooks,scripts}/**/*.{js,ts,tsx,jsx}\" --quiet --fix",
"generate:calendar": "ts-node ./scripts/generate-calendar",
"generate:members": "ts-node ./scripts/generate-members",
"check-lockfile": "ts-node ./scripts/check-lockfile"
},
"dependencies": {
@ -23,7 +22,6 @@
"@next/mdx": "11.0.1",
"@types/ldapjs": "^2.2.1",
"date-fns": "^2.11.1",
"ldapjs": "^2.3.1",
"ldapts": "^3.1.0",
"next": "11.0.1",
"next-mdx-remote": "3.0.4",

View File

@ -1,47 +0,0 @@
// import ldap from "ldapjs";
import { Client } from "ldapts";
export async function getMembers(year: string, term: string) {
// LDAPJS
// const client = ldap.createClient({
// url: [
// "ldap://ldap1.csclub.uwaterloo.ca",
// "ldap://ldap2.csclub.uwaterloo.ca",
// ],
// });
// client.bind("cn=root", "", (err) => {
// throw err;
// });
// const opts = {
// filter: `(&(objectClass=member)(term=${term}${year}))`,
// // scope: "sub",
// // attributes: ["dn", "sn", "cn"],
// };
// client.search("ou=People,dc=csclub,dc=uwaterloo,dc=ca", opts, (err, res) => {
// console.log("h3");
// res.on("searchEntry", (entry) => {
// console.log("entry: " + JSON.stringify(entry.object));
// });
// });
// client.unbind();
// LDAPTS
const url = "ldap://ldap1.csclub.uwaterloo.ca";
const searchDN = "ou=People,dc=csclub,dc=uwaterloo,dc=ca";
const client = new Client({
url,
});
try {
await client.bind("cn=root", "secret");
const { searchEntries, searchReferences } = await client.search(searchDN, {
scope: "sub",
filter: `(&(objectClass=member)(term=${term}${year}))`,
});
} catch (ex) {
throw ex;
} finally {
await client.unbind();
}
}
void getMembers("2020", "winter");