Skip to content

Commit

Permalink
Merge pull request #216 from binarymist/livereload-refactor
Browse files Browse the repository at this point in the history
Adjustments to livereload to stop (timeout) in prod
  • Loading branch information
ckarande authored Nov 10, 2020
2 parents 5ab0088 + 57817e3 commit dcd2a1d
Show file tree
Hide file tree
Showing 15 changed files with 197 additions and 96 deletions.
19 changes: 15 additions & 4 deletions app/routes/allocations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const AllocationsDAO = require("../data/allocations-dao").AllocationsDAO;
const {
environmentalScripts
} = require("../../config/config");

function AllocationsHandler (db) {
function AllocationsHandler(db) {
"use strict";

const allocationsDAO = new AllocationsDAO(db);
Expand All @@ -10,12 +13,20 @@ function AllocationsHandler (db) {
// Fix for A4 Insecure DOR - take user id from session instead of from URL param
const { userId } = req.session;
*/
const {userId} = req.params;
const { threshold } = req.query
const {
userId
} = req.params;
const {
threshold
} = req.query

allocationsDAO.getByUserIdAndThreshold(userId, threshold, (err, allocations) => {
if (err) return next(err);
return res.render("allocations", { userId, allocations });
return res.render("allocations", {
userId,
allocations,
environmentalScripts
});
});
};
}
Expand Down
22 changes: 16 additions & 6 deletions app/routes/benefits.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
const { BenefitsDAO } = require("../data/benefits-dao");

function BenefitsHandler (db) {
const {
BenefitsDAO
} = require("../data/benefits-dao");
const {
environmentalScripts
} = require("../../config/config");

function BenefitsHandler(db) {
"use strict";

const benefitsDAO = new BenefitsDAO(db);
Expand All @@ -15,13 +20,17 @@ function BenefitsHandler (db) {
users,
user: {
isAdmin: true
}
},
environmentalScripts
});
});
};

this.updateBenefits = (req, res, next) => {
const { userId, benefitStartDate } = req.body;
const {
userId,
benefitStartDate
} = req.body;

benefitsDAO.updateBenefits(userId, benefitStartDate, (error) => {

Expand All @@ -35,7 +44,8 @@ function BenefitsHandler (db) {
user: {
isAdmin: true
},
updateSuccess: true
updateSuccess: true,
environmentalScripts
};

return res.render("benefits", data);
Expand Down
29 changes: 22 additions & 7 deletions app/routes/contributions.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,27 @@
const ContributionsDAO = require("../data/contributions-dao").ContributionsDAO;
const {
environmentalScripts
} = require("../../config/config");

/* The ContributionsHandler must be constructed with a connected db */
function ContributionsHandler (db) {
function ContributionsHandler(db) {
"use strict";

const contributionsDAO = new ContributionsDAO(db);

this.displayContributions = (req, res, next) => {
const { userId } = req.session;
const {
userId
} = req.session;

contributionsDAO.getByUserId(userId, (error, contrib) => {
if (error) return next(error);

contrib.userId = userId; //set for nav menu items
return res.render("contributions", contrib);
return res.render("contributions", {
...contrib,
environmentalScripts
});
});
};

Expand All @@ -31,22 +39,26 @@ function ContributionsHandler (db) {
const afterTax = parseInt(req.body.afterTax);
const roth = parseInt(req.body.roth);
*/
const { userId } = req.session;
const {
userId
} = req.session;

//validate contributions
const validations = [isNaN(preTax), isNaN(afterTax), isNaN(roth), preTax < 0, afterTax < 0, roth < 0]
const isInvalid = validations.some(validation => validation)
if (isInvalid) {
return res.render("contributions", {
updateError: "Invalid contribution percentages",
userId
userId,
environmentalScripts
});
}
// Prevent more than 30% contributions
if (preTax + afterTax + roth > 30) {
return res.render("contributions", {
updateError: "Contribution percentages cannot exceed 30 %",
userId
userId,
environmentalScripts
});
}

Expand All @@ -55,7 +67,10 @@ function ContributionsHandler (db) {
if (err) return next(err);

contributions.updateSuccess = true;
return res.render("contributions", contributions);
return res.render("contributions", {
...contributions,
environmentalScripts
});
});

};
Expand Down
18 changes: 13 additions & 5 deletions app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ const ContributionsHandler = require("./contributions");
const AllocationsHandler = require("./allocations");
const MemosHandler = require("./memos");
const ResearchHandler = require("./research");

const {
environmentalScripts
} = require("../../config/config");
const ErrorHandler = require("./error").errorHandler;

const index = (app, db) => {
Expand Down Expand Up @@ -74,12 +76,18 @@ const index = (app, db) => {

// Handle redirect for learning resources link
app.get("/tutorial", (req, res) => {
return res.render("tutorial/a1");
return res.render("tutorial/a1", {
environmentalScripts
});
});

app.get("/tutorial/:page", (req, res) => {
const { page } = req.params
return res.render(`tutorial/${page}`);
const {
page
} = req.params
return res.render(`tutorial/${page}`, {
environmentalScripts
});
});

// Research Page
Expand Down
12 changes: 9 additions & 3 deletions app/routes/memos.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const MemosDAO = require("../data/memos-dao").MemosDAO;
const {
environmentalScripts
} = require("../../config/config");

function MemosHandler (db) {
function MemosHandler(db) {
"use strict";

const memosDAO = new MemosDAO(db);
Expand All @@ -15,13 +18,16 @@ function MemosHandler (db) {

this.displayMemos = (req, res, next) => {

const { userId } = req.session;
const {
userId
} = req.session;

memosDAO.getAllMemos((err, docs) => {
if (err) return next(err);
return res.render("memos", {
memosList: docs,
userId: userId
userId: userId,
environmentalScripts
});
});
};
Expand Down
36 changes: 29 additions & 7 deletions app/routes/profile.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
const ProfileDAO = require("../data/profile-dao").ProfileDAO;
const ESAPI = require('node-esapi')
const {
environmentalScripts
} = require("../../config/config");

/* The ProfileHandler must be constructed with a connected db */
function ProfileHandler (db) {
function ProfileHandler(db) {
"use strict";

const profile = new ProfileDAO(db);

this.displayProfile = (req, res, next) => {
const { userId } = req.session;
const {
userId
} = req.session;



Expand All @@ -25,13 +30,24 @@ function ProfileHandler (db) {
// the context of a URL in a link header
// doc.website = ESAPI.encoder().encodeForURL(doc.website)

return res.render("profile", doc);
return res.render("profile", {
...doc,
environmentalScripts
});
});
};

this.handleProfileUpdate = (req, res, next) => {

const {firstName, lastName, ssn, dob, address, bankAcc, bankRouting} = req.body;
const {
firstName,
lastName,
ssn,
dob,
address,
bankAcc,
bankRouting
} = req.body;

// Fix for Section: ReDoS attack
// The following regexPattern that is used to validate the bankRouting number is insecure and vulnerable to
Expand All @@ -54,11 +70,14 @@ function ProfileHandler (db) {
dob,
address,
bankAcc,
bankRouting
bankRouting,
environmentalScripts
});
}

const { userId } = req.session;
const {
userId
} = req.session;

profile.updateUser(
parseInt(userId),
Expand All @@ -78,7 +97,10 @@ function ProfileHandler (db) {
user.updateSuccess = true;
user.userId = userId;

return res.render("profile", user);
return res.render("profile", {
...user,
environmentalScripts
});
}
);

Expand Down
27 changes: 17 additions & 10 deletions app/routes/research.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,33 @@
const ResearchDAO = require("../data/research-dao").ResearchDAO;
const needle = require('needle');
const {
environmentalScripts
} = require("../../config/config");

function ResearchHandler (db) {
function ResearchHandler(db) {
"use strict";

const researchDAO = new ResearchDAO(db);

this.displayResearch = (req, res) => {

if (req.query.symbol) {
const url = req.query.url+req.query.symbol;
const url = req.query.url + req.query.symbol;
return needle.get(url, (error, newResponse) => {
if (!error && newResponse.statusCode == 200)
res.writeHead(200, {'Content-Type': 'text/html'});
res.write('<h1>The following is the stock information you requested.</h1>\n\n');
res.write('\n\n');
res.write(newResponse.body);
return res.end();
res.writeHead(200, {
'Content-Type': 'text/html'
});
res.write('<h1>The following is the stock information you requested.</h1>\n\n');
res.write('\n\n');
res.write(newResponse.body);
return res.end();
});
}

return res.render("research");

return res.render("research", {
environmentalScripts
});
};

}
Expand Down
Loading

0 comments on commit dcd2a1d

Please sign in to comment.