Skip to content
Snippets Groups Projects
Commit e8d668cd authored by michael.minelli's avatar michael.minelli
Browse files

SecurityMiddleware => Add check if connected

parent c0376ebd
No related branches found
No related tags found
No related merge requests found
...@@ -18,9 +18,15 @@ class SecurityMiddleware { ...@@ -18,9 +18,15 @@ class SecurityMiddleware {
return SecurityMiddleware._instance; return SecurityMiddleware._instance;
} }
//Check if at least ONE rule match. It's NOT an AND but it's a OR function. For IsJuryUnlock, IsStudentUnlock and IsScheduleUnlock it's cumulative // First check if connected then check if at least ONE rule match. It's NOT an AND but it's a OR function.
check(...checkTypes: Array<SecurityCheckType>): (req: ApiRequest, res: express.Response, next: express.NextFunction) => void { check(checkIfConnected: boolean, ...checkTypes: Array<SecurityCheckType>): (req: ApiRequest, res: express.Response, next: express.NextFunction) => void {
return async (req: ApiRequest, res: express.Response, next: express.NextFunction) => { return async (req: ApiRequest, res: express.Response, next: express.NextFunction) => {
if ( checkIfConnected ) {
if ( req.session.profile.userID === null ) {
return req.session.sendResponse(res, StatusCodes.UNAUTHORIZED);
}
}
let isAllowed = checkTypes.length === 0; let isAllowed = checkTypes.length === 0;
if ( !isAllowed ) { if ( !isAllowed ) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment