Skip to content

Commit a529f40

Browse files
committed
add field into authentication token
1 parent bef18d3 commit a529f40

File tree

4 files changed

+18
-6
lines changed

4 files changed

+18
-6
lines changed

src/account/account-manager.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@ const generateStudentID = (Wilma2SID) => {
8686

8787
account.validateAccountGetStudentID(response)
8888
.then(studentID => {
89-
return resolve(studentID);
89+
const teacher = utility.parsers.parseStudentId(studentID);
90+
return resolve([studentID, teacher]);
9091
})
9192
.catch(err => {
9293
return reject(err);
@@ -105,8 +106,8 @@ const StartSession = async (login = { Username: String, Password: String, Curren
105106
Wilma2LoginID: details.raw, // You gotta be fucking kidding me
106107
}).then(session => {
107108
generateStudentID(session.value[0])
108-
.then(studentID => {
109-
const token = authentication.signToken({ Wilma2SID: session.value[0], StudentID: studentID, username: login.Username.toLowerCase() })
109+
.then(([studentID, teacher]) => {
110+
const token = authentication.signToken({ Wilma2SID: session.value[0], StudentID: studentID, username: login.Username.toLowerCase(), isTeacher: teacher })
110111
return resolve({ token: token, reset: true });
111112
})
112113
.catch(err => {

src/database/authentication.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ const signToken = (payload = {}) => {
88

99
const validateToken = (req, res) => {
1010
return new Promise((resolve, reject) => {
11-
const a = ['Wilma2SID', 'StudentID', 'username', 'iat'];
11+
const a = ['Wilma2SID', 'StudentID', 'username', 'iat', 'isTeacher'];
1212
const token = req.headers.token;
13+
console.log(token);
1314

1415
if (!token) {
1516
res.status(401).json({ err: 'Missing authentication parameters: ["token"]', status: 401 });

src/requests/gradebook.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@ const { grades } = require('../requests/responses');
66

77
const getGradeBook = (auth, limit, filter) => {
88
return new Promise((resolve, reject) => {
9-
var options = {
9+
console.log(auth)
10+
if (auth.isTeacher) {
11+
return resolve({})
12+
}
13+
14+
const options = {
1015
'method': 'GET',
1116
'url': `https://espoo.inschool.fi/choices?view=gradebook`,
1217
'headers': {

src/utility/utility.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,10 @@ const parseStudent = (raw) => {
5858
});
5959
}
6060

61+
const parseStudentId = (studentId) => {
62+
return studentId.split(':')[0] != 'student'
63+
}
64+
6165
const parseTitle = (raw) => {
6266
return new Promise((resolve, reject) => {
6367
try {
@@ -92,6 +96,7 @@ module.exports = {
9296
parsers: {
9397
parseStudent,
9498
parseTitle,
95-
parseName
99+
parseName,
100+
parseStudentId
96101
}
97102
}

0 commit comments

Comments
 (0)