working ish website

This commit is contained in:
Siwat Sirichai 2024-05-05 18:13:58 +07:00
parent 5540ac6d81
commit b194d2031d
8 changed files with 271 additions and 6 deletions

View file

@ -33,7 +33,25 @@ passport.use(
console.log("user:", user);
profile["dn"] = user.dn;
profile["memberOf"] = user.memberOf;
return done(null, profile);
// Is this user a student or a parent?
profile["userType"] = directory.getUserTypeFromDN(profile["dn"]);
let user_type = profile["userType"];
// If the user is a student, query the student's primary parent
// and store the parent's UPN in the session
if (user_type === directory.USER_TYPE.STUDENT) {
let student = await directory.queryUser(username, ["primaryParent"]);
profile["primaryParent"] = student.primaryParent;
}
// If the user is a parent, query the parent's students
// and store the students' UPNs in the session
else if (user_type === directory.USER_TYPE.PARENT) {
let students = await directory.listStudents(username);
profile["students"] = students;
} else {
console.log("Unknown user type");
}
return done(null, profile); // Return the user's profile
}
)
);