Skip to content

Commit 757032c

Browse files
authored
Merge pull request #174 from hackmcgill/bug/162
Bug/162
2 parents 3815f2d + e39f78c commit 757032c

8 files changed

Lines changed: 82 additions & 84 deletions

middlewares/account.middleware.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ const Constants = {
2828
*/
2929
function parsePatch(req, res, next) {
3030
delete req.body.id;
31-
next();
31+
return next();
3232
}
3333

3434
/**
@@ -68,7 +68,7 @@ function parseAccount(req, res, next) {
6868

6969
req.body.accountDetails = accountDetails;
7070

71-
next();
71+
return next();
7272
}
7373

7474
/**
@@ -79,13 +79,13 @@ function parseAccount(req, res, next) {
7979
*/
8080
async function updatePassword(req, res, next) {
8181
req.body.account = await Services.Account.updatePassword(req.body.decodedToken.accountId, req.body.password);
82-
next();
82+
return next();
8383
}
8484

8585
// TODO: fix when new permission system is created
8686
async function addDefaultHackerPermissions(req, res, next) {
8787
// await Services.RoleBinding.createRoleBinding(req.);
88-
next();
88+
return next();
8989
}
9090

9191
/**
@@ -112,7 +112,7 @@ async function addAccount(req, res, next) {
112112
}
113113
const account = await Services.Account.addOneAccount(accountDetails);
114114
req.body.account = account;
115-
next();
115+
return next();
116116
}
117117

118118
/**
@@ -124,9 +124,9 @@ async function addAccount(req, res, next) {
124124
async function updateAccount(req, res, next) {
125125
const account = await Services.Account.updateOne(req.params.id, req.body);
126126
if (account) {
127-
next();
127+
return next();
128128
} else {
129-
next({
129+
return next({
130130
status: 404,
131131
message: Constants.Error.ACCOUNT_404_MESSAGE,
132132
data: {

middlewares/auth.middleware.js

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ function login(req, res, next) {
5454
error: {}
5555
});
5656
}
57-
next();
57+
return next();
5858
});
5959
})(req, res, next);
6060
}
@@ -66,15 +66,15 @@ function login(req, res, next) {
6666
function ensureAuthenticated() {
6767
return function (req, res, next) {
6868
if (req.isUnauthenticated()) {
69-
next({
69+
return next({
7070
status: 401,
7171
message: Constants.Error.AUTH_401_MESSAGE,
7272
error: {
7373
route: req.path
7474
}
7575
});
7676
} else {
77-
next();
77+
return next();
7878
}
7979
};
8080
}
@@ -89,19 +89,19 @@ function ensureAuthorized(findByIdFns) {
8989
Services.Auth.ensureAuthorized(req, findByIdFns).then(
9090
(auth) => {
9191
if (!auth) {
92-
next({
92+
return next({
9393
status: 403,
9494
message: Constants.Error.AUTH_403_MESSAGE,
9595
error: {
9696
route: req.path
9797
}
9898
});
9999
} else {
100-
next();
100+
return next();
101101
}
102102
},
103103
(err) => {
104-
next(err);
104+
return next(err);
105105
}
106106
);
107107
};
@@ -122,7 +122,7 @@ async function retrieveRoleBindings(req, res, next) {
122122
})
123123
}
124124
req.roleBindings = roleBindings;
125-
next();
125+
return next();
126126
}
127127

128128
/**
@@ -144,9 +144,9 @@ async function sendResetPasswordEmailMiddleware(req, res, next) {
144144
if (mailData !== undefined) {
145145
Services.Email.send(mailData, (err) => {
146146
if (err) {
147-
next(err);
147+
return next(err);
148148
} else {
149-
next();
149+
return next();
150150
}
151151
});
152152
} else {
@@ -156,7 +156,7 @@ async function sendResetPasswordEmailMiddleware(req, res, next) {
156156
}
157157
} else {
158158
//Didn't find the user, but we don't want to throw an error because someone might be trying to see who has an account.
159-
next();
159+
return next();
160160
}
161161
}
162162

@@ -180,9 +180,9 @@ async function sendConfirmAccountEmailMiddleware(req, res, next) {
180180
if (mailData !== undefined) {
181181
Services.Email.send(mailData, (err) => {
182182
if (err) {
183-
next(err);
183+
return next(err);
184184
} else {
185-
next();
185+
return next();
186186
}
187187
});
188188
} else {
@@ -218,9 +218,9 @@ async function resendConfirmAccountEmail(req, res, next) {
218218
if (mailData !== undefined) {
219219
Services.Email.send(mailData, (err) => {
220220
if (err) {
221-
next(err);
221+
return next(err);
222222
} else {
223-
next();
223+
return next();
224224
}
225225
});
226226
} else {
@@ -240,10 +240,10 @@ async function resendConfirmAccountEmail(req, res, next) {
240240
function parseResetToken(req, res, next) {
241241
jwt.verify(req.body['x-reset-token'], process.env.JWT_RESET_PWD_SECRET, function (err, decoded) {
242242
if (err) {
243-
next(err);
243+
return next(err);
244244
} else {
245245
req.body.decodedToken = decoded;
246-
next();
246+
return next();
247247
}
248248
});
249249
}
@@ -260,13 +260,13 @@ function parseAccountConfirmationToken(req, res, next) {
260260
if (!!req.body.token) {
261261
jwt.verify(req.body.token, process.env.JWT_CONFIRM_ACC_SECRET, function (err, decoded) {
262262
if (err) {
263-
next(err);
263+
return next(err);
264264
} else {
265265
req.body.decodedToken = decoded;
266266
}
267267
});
268268
}
269-
next();
269+
return next();
270270
}
271271

272272
/**
@@ -279,10 +279,10 @@ async function getAccountTypeFromConfirmationToken(req, res, next) {
279279
const confirmationObj = await Services.AccountConfirmation.findById(req.body.decodedToken.accountConfirmationId);
280280
if (confirmationObj) {
281281
req.body.accountType = confirmationObj.accountType;
282-
next();
282+
return next();
283283
} else {
284284
//Either the token was already used, it's invalid, or user does not exist.
285-
next({
285+
return next({
286286
status: 401,
287287
message: Constants.Error.ACCOUNT_TOKEN_401_MESSAGE,
288288
error: {}
@@ -301,10 +301,10 @@ async function validateResetToken(req, res, next) {
301301
const userObj = await Services.Account.findById(req.body.decodedToken.accountId);
302302
if (resetObj && userObj) {
303303
req.body.user = userObj;
304-
next();
304+
return next();
305305
} else {
306306
//Either the token was already used, it's invalid, or user does not exist.
307-
next({
307+
return next({
308308
status: 401,
309309
message: Constants.Error.ACCOUNT_TOKEN_401_MESSAGE,
310310
error: {}
@@ -326,10 +326,10 @@ async function validateConfirmationToken(req, res, next) {
326326
userObj.accountType = confirmationObj.accountType;
327327
await Services.Account.updateOne(confirmationObj.accountId, userObj);
328328
req.body.user = userObj;
329-
next();
329+
return next();
330330
} else {
331331
//Either the token was already used, it's invalid, or user does not exist.
332-
next({
332+
return next({
333333
status: 401,
334334
message: Constants.Error.ACCOUNT_TOKEN_401_MESSAGE,
335335
error: {}
@@ -351,7 +351,7 @@ async function validateConfirmationTokenWithoutAccount(req, res, next) {
351351
req.body.accountDetails.accountType = confirmationObj.accountType;
352352
}
353353
}
354-
next();
354+
return next();
355355
}
356356

357357

@@ -364,10 +364,10 @@ async function validateConfirmationTokenWithoutAccount(req, res, next) {
364364
function deleteResetToken(req, res, next) {
365365
Services.ResetPasswordToken.deleteToken(req.body.decodedToken.resetId).then(
366366
() => {
367-
next();
367+
return next();
368368
},
369369
(err) => {
370-
next(err);
370+
return next(err);
371371
}
372372
);
373373
}
@@ -384,7 +384,7 @@ async function addCreationRoleBindings(req, res, next) {
384384
await Services.RoleBinding.createRoleBindingByRoleName(req.body.account.id, roleName);
385385
// Add default account role bindings
386386
await Services.RoleBinding.createRoleBindingByRoleName(req.body.account.id, Constants.Role.accountRole.name);
387-
next();
387+
return next();
388388
}
389389

390390
/**
@@ -394,7 +394,7 @@ async function addCreationRoleBindings(req, res, next) {
394394
function createRoleBindings(roleName = undefined) {
395395
return Middleware.Util.asyncMiddleware(async (req, res, next) => {
396396
await Services.RoleBinding.createRoleBindingByRoleName(req.user.id, roleName);
397-
next();
397+
return next();
398398
});
399399
}
400400

@@ -407,7 +407,7 @@ function createRoleBindings(roleName = undefined) {
407407
async function retrieveRoles(req, res, next) {
408408
const roles = await Services.Role.getAll();
409409
req.roles = roles;
410-
next();
410+
return next();
411411
}
412412

413413
module.exports = {

middlewares/hacker.middleware.js

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const Constants = {
2626
*/
2727
function parsePatch(req, res, next) {
2828
delete req.body.id;
29-
next();
29+
return next();
3030
}
3131

3232
/**
@@ -68,7 +68,7 @@ function parseHacker(req, res, next) {
6868

6969
req.body.hackerDetails = hackerDetails;
7070

71-
next();
71+
return next();
7272
}
7373

7474
/**
@@ -119,7 +119,7 @@ function parseConfirmation(req, res, next) {
119119
*/
120120
function addDefaultStatus(req, res, next) {
121121
req.body.hackerDetails.status = "Applied";
122-
next();
122+
return next();
123123
}
124124

125125
/**
@@ -131,24 +131,24 @@ function addDefaultStatus(req, res, next) {
131131
async function validateConfirmedStatus(req, res, next) {
132132
const account = await Services.Account.findById(req.body.accountId);
133133
if (!account) {
134-
next({
134+
return next({
135135
status: 404,
136136
message: Constants.Error.ACCOUNT_404_MESSAGE,
137137
error: {}
138138
});
139139
} else if (!account.confirmed) {
140-
next({
140+
return next({
141141
status: 403,
142142
message: Constants.Error.ACCOUNT_403_MESSAGE,
143143
error: {}
144144
});
145145
} else if (account.accountType !== Constants.General.HACKER) {
146-
next({
146+
return next({
147147
status: 409,
148148
message: Constants.Error.ACCOUNT_TYPE_409_MESSAGE
149149
});
150150
} else {
151-
next();
151+
return next();
152152
}
153153
}
154154

@@ -164,9 +164,9 @@ function ensureAccountLinkedToHacker(req, res, next) {
164164
(hacker) => {
165165
req.hacker = hacker;
166166
if (hacker && req.user && String.toString(hacker.accountId) === String.toString(req.user.id)) {
167-
next();
167+
return next();
168168
} else {
169-
next({
169+
return next({
170170
status: 403,
171171
message: Constants.Error.AUTH_403_MESSAGE,
172172
error: {}
@@ -191,7 +191,7 @@ async function uploadResume(req, res, next) {
191191
"application.portfolioURL.resume": gcfilename
192192
}
193193
});
194-
next();
194+
return next();
195195
}
196196

197197
/**
@@ -211,7 +211,7 @@ async function downloadResume(req, res, next) {
211211
error: {}
212212
});
213213
}
214-
next();
214+
return next();
215215
}
216216
/**
217217
* Sends a preset email to a user if a status change occured.
@@ -266,10 +266,10 @@ async function updateStatusIfApplicationCompleted(req, res, next) {
266266
}
267267
Services.Email.sendStatusUpdate(account.email, Constants.General.HACKER_STATUS_APPLIED, next);
268268
} else {
269-
next();
269+
return next();
270270
}
271271
} else {
272-
next({
272+
return next({
273273
status: 404,
274274
message: Constants.Error.HACKER_404_MESSAGE,
275275
data: {
@@ -338,9 +338,9 @@ async function updateHacker(req, res, next) {
338338
});
339339
}
340340
req.email = acct.email;
341-
next();
341+
return next();
342342
} else {
343-
next({
343+
return next({
344344
status: 404,
345345
message: Constants.Error.HACKER_404_MESSAGE,
346346
data: {
@@ -397,9 +397,9 @@ async function createHacker(req, res, next) {
397397
async function checkDuplicateAccountLinks(req, res, next) {
398398
const hacker = await Services.Hacker.findByAccountId(req.body.accountId);
399399
if (!hacker) {
400-
next();
400+
return next();
401401
} else {
402-
next({
402+
return next({
403403
status: 409,
404404
message: Constants.Error.HACKER_ID_409_MESSAGE,
405405
data: {

0 commit comments

Comments
 (0)