Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added 404 page feature #200

Open
wants to merge 1 commit into
base: feature/187
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions app/data/allocations-dao.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
const UserDAO = require("./user-dao").UserDAO;

/* The AllocationsDAO must be constructed with a connected database object */
const AllocationsDAO = function(db){
const AllocationsDAO = function(db) {

"use strict";

Expand Down Expand Up @@ -90,7 +90,7 @@ const AllocationsDAO = function(db){
let doneCounter = 0;
const userAllocations = [];

allocations.forEach( alloc => {
allocations.forEach(alloc => {
userDAO.getUserById(alloc.userId, (err, user) => {
if (err) return callback(err, null);

Expand Down
4 changes: 3 additions & 1 deletion app/data/benefits-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,6 @@ function BenefitsDAO(db) {
};
}

module.exports = { BenefitsDAO };
module.exports = {
BenefitsDAO
};
6 changes: 4 additions & 2 deletions app/data/contributions-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ function ContributionsDAO(db) {
};

contributionsDB.update({
userId
userId
},
contributions, {
upsert: true
Expand Down Expand Up @@ -83,4 +83,6 @@ function ContributionsDAO(db) {
};
}

module.exports = { ContributionsDAO };
module.exports = {
ContributionsDAO
};
4 changes: 3 additions & 1 deletion app/data/memos-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,6 @@ function MemosDAO(db) {

}

module.exports = { MemosDAO };
module.exports = {
MemosDAO
};
4 changes: 3 additions & 1 deletion app/data/profile-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ function ProfileDAO(db) {
};
}

module.exports = { ProfileDAO };
module.exports = {
ProfileDAO
};
4 changes: 3 additions & 1 deletion app/data/research-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ function ResearchDAO(db) {
}
}

module.exports = { ResearchDAO };
module.exports = {
ResearchDAO
};
6 changes: 4 additions & 2 deletions app/data/user-dao.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,10 @@ function UserDAO(db) {
}, {
new: true
},
(err, data) => err ? callback(err, null) : callback(null, data.value.seq));
(err, data) => err ? callback(err, null) : callback(null, data.value.seq));
};
}

module.exports = { UserDAO };
module.exports = {
UserDAO
};
15 changes: 11 additions & 4 deletions app/routes/allocations.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const AllocationsDAO = require("../data/allocations-dao").AllocationsDAO;

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

const allocationsDAO = new AllocationsDAO(db);
Expand All @@ -10,12 +10,19 @@ 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
});
});
};
}
Expand Down
11 changes: 8 additions & 3 deletions app/routes/benefits.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const { BenefitsDAO } = require("../data/benefits-dao");
const {
BenefitsDAO
} = require("../data/benefits-dao");

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

const benefitsDAO = new BenefitsDAO(db);
Expand All @@ -21,7 +23,10 @@ function BenefitsHandler (db) {
};

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

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

Expand Down
10 changes: 7 additions & 3 deletions app/routes/contributions.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
const ContributionsDAO = require("../data/contributions-dao").ContributionsDAO;

/* 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);
Expand All @@ -31,7 +33,9 @@ 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]
Expand Down
6 changes: 4 additions & 2 deletions app/routes/error.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Error handling middleware

const errorHandler = (err, req, res,next) => {
const errorHandler = (err, req, res, next) => {

"use strict";

Expand All @@ -12,4 +12,6 @@ const errorHandler = (err, req, res,next) => {
});
};

module.exports = { errorHandler };
module.exports = {
errorHandler
};
11 changes: 9 additions & 2 deletions app/routes/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,15 +76,22 @@ const index = (app, db) => {
app.get("/tutorial", (req, res) => {
return res.render("tutorial/a1");
});

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

// Research Page
app.get("/research", isLoggedIn, researchHandler.displayResearch);

//404 Page
app.get("*", (req, res) => {
return res.render("404");
});

// Error handling middleware
app.use(ErrorHandler);
};
Expand Down
6 changes: 4 additions & 2 deletions app/routes/memos.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const MemosDAO = require("../data/memos-dao").MemosDAO;

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

const memosDAO = new MemosDAO(db);
Expand All @@ -15,7 +15,9 @@ 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);
Expand Down
20 changes: 16 additions & 4 deletions app/routes/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ const ProfileDAO = require("../data/profile-dao").ProfileDAO;
const ESAPI = require('node-esapi')

/* 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 @@ -31,7 +33,15 @@ function ProfileHandler (db) {

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 @@ -58,7 +68,9 @@ function ProfileHandler (db) {
});
}

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

profile.updateUser(
parseInt(userId),
Expand Down
20 changes: 11 additions & 9 deletions app/routes/research.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,27 @@
const ResearchDAO = require("../data/research-dao").ResearchDAO;
const needle = require('needle');

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");
};

Expand Down
22 changes: 16 additions & 6 deletions app/routes/session.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const UserDAO = require("../data/user-dao").UserDAO;
const AllocationsDAO = require("../data/allocations-dao").AllocationsDAO;

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

const userDAO = new UserDAO(db);
Expand All @@ -22,16 +22,16 @@ function SessionHandler (db) {
this.isAdminUserMiddleware = (req, res, next) => {
if (req.session.userId) {
return userDAO.getUserById(req.session.userId, (err, user) => user && user.isAdmin ? next() : res.redirect("/login"));
}
}
console.log("redirecting to login");
return res.redirect("/login");

};

this.isLoggedInMiddleware = (req, res, next) => {
if (req.session.userId) {
return next();
}
}
console.log("redirecting to login");
return res.redirect("/login");
};
Expand All @@ -45,7 +45,10 @@ function SessionHandler (db) {
};

this.handleLoginRequest = (req, res, next) => {
const { userName, password } = req.body
const {
userName,
password
} = req.body
userDAO.validateLogin(userName, password, (err, user) => {
const errorMessage = "Invalid username and/or password";
const invalidUserNameErrorMessage = "Invalid username";
Expand Down Expand Up @@ -173,7 +176,14 @@ function SessionHandler (db) {

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

const { email, userName, firstName, lastName, password, verify } = req.body;
const {
email,
userName,
firstName,
lastName,
password,
verify
} = req.body;

// set these up in case we have an error case
const errors = {
Expand Down
Loading