Skip to content
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
9 changes: 9 additions & 0 deletions Back-end/controller/Main.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ server.get('/index', (req, res) => {
res.sendFile(path.resolve(__dirname + '/../../Front-end/index.html'));
});


server.get('/un-authorized', (req, res) => {
res.sendFile(path.resolve(__dirname + '/../../Front-end/401.html'));
});

server.get('*', (req, res) => {
res.sendFile(path.resolve(__dirname + '/../../Front-end/404.html'));
});

/**
* Function performed when there is a new socket connection.
*
Expand Down
4 changes: 4 additions & 0 deletions Back-end/database/DatabaseConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@ module.exports = class DatabaseConnection {
try {
if (!mongoose.connection.readyState) {
await mongoose.connect(process.env.MONGODB_URI, { useNewUrlParser: true, useUnifiedTopology: true });

console.log('Connected to MongoDB');
}
} catch (ex) {

console.log('Failed to connect to MongoDB');
throw ex;
}
}
Expand Down
15 changes: 13 additions & 2 deletions Back-end/service/AuthenticationService.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,25 @@ module.exports = class AuthenticationService {
try {
let token = req.cookies.access_token;

console.log(token);

if (!token || token.split('.').length !== 3) {
return next(new ErrorResponse(401, 'Invalid token format.', null));
}


if (!token) throw new ErrorResponse(401, 'No token provided.', null);

jwt.verify(token, process.env.JWT_SECRET, (err, decoded) => {
if (err) throw new ErrorResponse(500, 'Failed to authenticate token.', null);
if (err) {
console.log(err);
return next( ErrorResponse(500, 'Failed to authenticate token.', null));
}

req.userId = decoded.id;

req.userId = decoded.id;
next();

});
} catch (ex) {
throw ex;
Expand Down
2 changes: 1 addition & 1 deletion Back-end/service/CodeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ module.exports = class CodeService {

return files;
} else {
throw new ErrorResponse(401, "You don't have permisson to access this code", null);
throw new ErrorResponse(401, "You don't have permisson to access this code", null);
}
} catch (ex) {
throw ex;
Expand Down
15 changes: 15 additions & 0 deletions Front-end/401.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html >
<title>401 - Un-Athorized</title>
<!--CODE IMPORT-->
<link rel="stylesheet" type="text/css" href="./css/404.css" />
<!--END CODE IMPORT-->

<body>
<div class="container">
<h1>401</h1>
<p>Oops! Seems that you don't have access to this page</p>
<a href="/" class="btn">Back To Home</a>
</div>
<script src="./js/404.js"></script>
</body>
</html>
15 changes: 15 additions & 0 deletions Front-end/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<html >
<title>404 - Page Not Found</title>
<!--CODE IMPORT-->
<link rel="stylesheet" type="text/css" href="./css/404.css" />
<!--END CODE IMPORT-->

<body>
<div class="container">
<h1>404</h1>
<p>Oops! The page you're looking for doesn't exist.</p>
<a href="/" class="btn">Go Back Home</a>
</div>
<script src="./js/404.js"></script>
</body>
</html>
42 changes: 42 additions & 0 deletions Front-end/css/404.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/* Basic reset */
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}

body {
font-family: 'Arial', sans-serif;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #f4f4f4;
}

.container {
text-align: center;
}

h1 {
font-size: 5rem;
color: #00BFFF;
}

p {
font-size: 1.5rem;
margin-bottom: 20px;
font-family: Verdana, Geneva, Tahoma, sans-serif;
}

.btn {
padding: 10px 20px;
background-color: #00BFFF;
color: #fff;
text-decoration: none;
border-radius: 5px;
}

.btn:hover {
background-color: #00e1ff;
}
4 changes: 4 additions & 0 deletions Front-end/js/404.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// Redirect to homepage after 5 seconds
setTimeout(function() {
window.location.href = '/';
}, 5000);
2 changes: 1 addition & 1 deletion Front-end/js/file-tree.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ function getCodeFiles() {

switch (statusCode) {
case 401:
$('#loginModal').modal('show');
window.location.href = '/un-authorized';
break;
case 501:
toastr.error("You don't have permission for access this code.");
Expand Down
Loading