Skip to content

Commit

Permalink
Don't scrape if no username/password
Browse files Browse the repository at this point in the history
Instead of having the frontend rely on the scraper giving a success
(a login failure would redirect the user to the login page)
and a blank (default) tableData in the case of a blank username or
password, the backend now detects this and automatically gives
a default response.
  • Loading branch information
psvenk committed Mar 30, 2020
1 parent 3c02e71 commit 6138dfc
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,8 +196,23 @@ app.post('/data', async (req, res) => {
//
// Get data from scraper:
//
response = await scraper.scrape_student(req.session.username, req.session.password, req.body.quarter);
res.send(response);
if (!req.session.username || !req.session.password) {
res.send({
classes: [],
recent: {
recentActivityArray: [],
recentAttendanceArray: []
},
overview: [],
username: "",
quarter: "0"
});
}
else {
res.send(scraper.scrape_student(
req.session.username, req.session.password, req.body.quarter
));
}

// If "out" command-line argument provided, save JSON at the given path
if (args.hasOwnProperty("out")) {
Expand Down

0 comments on commit 6138dfc

Please sign in to comment.