Skip to content

Commit

Permalink
Merge pull request #17 from noremacsim/1.1.0/bug/Fix_requested_path
Browse files Browse the repository at this point in the history
1.1.0 - Move Core Features
  • Loading branch information
noremacsim authored Nov 29, 2022
2 parents f471f49 + 35319f0 commit 972fafb
Show file tree
Hide file tree
Showing 41 changed files with 396 additions and 213 deletions.
4 changes: 3 additions & 1 deletion .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ package-lock.json
package.json
postman.json
readme.md
SECURITY.md
SECURITY.md
CODE_OF_CONDUCT.md
CONTRIBUTING.md
2 changes: 2 additions & 0 deletions App/controllers/companyController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const {ValidationError} = require('sequelize');
const Boom = require('boom');

module.exports = {
name: 'company',

newCompany: async (request, h) => {
if (!request.payload.name) {
throw Boom.badRequest('Company Name Required');
Expand Down
2 changes: 2 additions & 0 deletions App/controllers/feedController.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ const {sequelize} = require(path.join(__dirname, '../../Core/models/'));
const {QueryTypes} = require('sequelize');

module.exports = {
name: 'feed',

posts: async (request, h, raw = false) => {
// We should group the users from company then group then firends to get posts
// If a user is part of a company/group we should return global posts in that scope
Expand Down
2 changes: 2 additions & 0 deletions App/controllers/friendsController.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ const {ValidationError, QueryTypes} = require('sequelize');
const Boom = require('boom');

module.exports = {
name: 'friends',

newRequest: async (request, h) => {
if (!request.payload.friend_ID) {
throw Boom.badRequest('We need a friend_Id');
Expand Down
2 changes: 2 additions & 0 deletions App/controllers/groupController.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ const {ValidationError} = require('sequelize');
const Boom = require('boom');

module.exports = {
name: 'group',

newGroup: async (request, h) => {
if (!request.payload.name) {
throw Boom.badRequest('Group Name Required');
Expand Down
2 changes: 2 additions & 0 deletions App/controllers/homeController.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ const path = require('path');
const Feed = require(path.join(__dirname, '../controllers/feedController'));

module.exports = {
name: 'home',

main: async (request, h) => {
const posts = await Feed.posts(request, h, true);
return h.simsView('home/main', {posts: posts ?? {}}, request);
Expand Down
2 changes: 2 additions & 0 deletions App/controllers/publicController.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
module.exports = {
name: 'public',

home: async (request, h) => {
return h.fullView('welcome', null);
},
Expand Down
9 changes: 9 additions & 0 deletions App/controllers/userController.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@ const {ValidationError} = require('sequelize');
const Boom = require('boom');

module.exports = {
name: 'user',

signinView: async (request, h) => {
if (
request.state.twoFAPassed === true &&
request.state.isLoggedIn === true
) {
return h.redirect(`/`);
}

if (
request.state.twoFAPassed === false &&
request.state.isLoggedIn === true
Expand Down
2 changes: 1 addition & 1 deletion App/routes/friends.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ const Friends = require(path.join(
__dirname,
'../controllers/friendsController'
));
const {middleware} = require(path.join(__dirname, '../../Core/middleware'));
const middleware = require(path.join(__dirname, '../../Core/middleware'));

module.exports = [
{
Expand Down
4 changes: 2 additions & 2 deletions App/routes/home.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
const path = require('path');
const Home = require(path.join(__dirname, '../controllers/homeController'));
const {middleware} = require(path.join(__dirname, '../../Core/middleware'));
const {Middleware} = require(path.join(__dirname, '../../Core/'));

module.exports = [
{
method: 'GET',
path: '/',
config: {
handler: async function (request, h) {
const connect = await middleware.auth(request, h);
const connect = await Middleware.auth(request, h);
if (connect === 'passed') {
return Home.main(request, h);
}
Expand Down
2 changes: 1 addition & 1 deletion App/routes/posts.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const path = require('path');
const Feed = require(path.join(__dirname, '../controllers/feedController'));
const {middleware} = require(path.join(__dirname, '../../Core/middleware'));
const middleware = require(path.join(__dirname, '../../Core/middleware'));

module.exports = [
{
Expand Down
68 changes: 4 additions & 64 deletions App/routes/user.js
Original file line number Diff line number Diff line change
@@ -1,72 +1,12 @@
const path = require('path');
const User = require(path.join(__dirname, '../controllers/userController'));
const {middleware} = require(path.join(__dirname, '../../Core/middleware'));
const {Controllers} = require(path.join(__dirname, '../../Core/'));
const middleware = require(path.join(__dirname, '../../Core/middleware'));

module.exports = [
{
method: 'POST',
path: '/user/login',
handler: User.login,
config: {
description: 'Login User',
},
},
{
method: 'POST',
path: '/user/logout',
handler: User.logout,
config: {
description: 'Logout User',
},
},
{
method: 'POST',
path: '/user/register',
handler: User.register,
config: {
description: 'Register User',
},
},
{
method: 'GET',
path: '/user',
handler: User.details,
config: {
pre: [{method: middleware.apiAuth}],
description: 'User Details',
},
},
{
method: 'POST',
path: '/user/update',
handler: User.update,
config: {
pre: [{method: middleware.apiAuth}],
description: 'Update User',
},
},
{
method: 'GET',
path: '/user/2fa/new',
handler: User.new2Fa,
config: {
pre: [{method: middleware.apiAuth}],
description: 'User Details',
},
},
{
method: 'POST',
path: '/user/2fa/validate',
handler: User.enable2Fa,
config: {
pre: [{method: middleware.twofaCheck}],
description: 'User Details',
},
},
{
method: 'GET',
path: '/user/login',
handler: User.signinView,
handler: Controllers.user.signinView,
config: {
description: 'Login User',
},
Expand All @@ -78,7 +18,7 @@ module.exports = [
handler: async function (request, h) {
const connect = await middleware.auth(request, h);
if (connect === 'passed') {
return User.settingsView(request, h);
return Controllers.user.settingsView(request, h);
}
return connect;
},
Expand Down
152 changes: 56 additions & 96 deletions App/views/error/404.html
Original file line number Diff line number Diff line change
@@ -1,106 +1,66 @@
<style>
* {
font-family: Google sans, Arial;
}

html,
body {
margin: 0;
padding: 0;
}

.flex-container {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
color: white;
animation: colorSlide 15s cubic-bezier(0.075, 0.82, 0.165, 1) infinite;
<html lang="en">
<head>
<meta charset="utf-8" />
<title>404 Page Not Found</title>
<style type="text/css">
::selection {
background-color: #e13300;
color: white;
}
::-moz-selection {
background-color: #e13300;
color: white;
}

.text-center {
text-align: center;
h1,
h3 {
margin: 10px;
cursor: default;
body {
background-color: #fff;
margin: 40px;
font: 13px/20px normal Helvetica, Arial, sans-serif;
color: #4f5155;
}

.fade-in {
animation: fadeIn 2s ease infinite;
}
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

h1 {
font-size: 8em;
transition: font-size 200ms ease-in-out;
border-bottom: 1px dashed white;

span#digit1 {
animation-delay: 200ms;
}
span#digit2 {
animation-delay: 300ms;
}
span#digit3 {
animation-delay: 400ms;
}
color: #444;
background-color: transparent;
border-bottom: 1px solid #d0d0d0;
font-size: 19px;
font-weight: normal;
margin: 0 0 14px;
padding: 14px 15px 10px;
}

button {
border: 1px solid white;
background: transparent;
outline: none;
padding: 10px 20px;
font-size: 1.1rem;
font-weight: bold;
color: white;
text-transform: uppercase;
transition: background-color 200ms ease-in;
margin: 20px 0;

&:hover {
background-color: white;
color: #555;
cursor: pointer;
}
code {
font-family: Consolas, Monaco, Courier New, Courier, monospace;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #d0d0d0;
color: #002166;
display: block;
margin: 14px 0;
padding: 12px 10px;
}
}
}

@keyframes colorSlide {
0% {
background-color: #152a68;
}
25% {
background-color: royalblue;
}
50% {
background-color: seagreen;
}
75% {
background-color: tomato;
}
100% {
background-color: #152a68;
}
}
#container {
margin: 10px;
border: 1px solid #d0d0d0;
box-shadow: 0 0 8px #d0d0d0;
}

@keyframes fadeIn {
from {
opacity: 0;
}
100% {
opacity: 1;
}
}
</style>
<div class="flex-container">
<div class="text-center">
<h1>
<span class="fade-in" id="digit1">4</span>
<span class="fade-in" id="digit2">0</span>
<span class="fade-in" id="digit3">4</span>
</h1>
<h3 class="fadeIn">PAGE NOT FOUND</h3>
<button type="button" name="button">Return To Home</button>
</div>
</div>
p {
margin: 12px 15px;
}
</style>
</head>
<body>
<div id="container">
<h1>404 Page Not Found</h1>
<p>The page you requested was not found.</p>
</div>
</body>
</html>
17 changes: 17 additions & 0 deletions Core/controllers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const fs = require('fs');
const path = require('path');

let controller;
let Controllers = [];

fs.readdirSync(path.join(__dirname, '../../App/controllers/'))
.filter((file) => file !== 'index.js')
.forEach((file) => {
controller = require(path.join(
__dirname + '../../../App/controllers/',
file
));
Controllers[controller.name] = controller;
});

module.exports = Controllers;
Loading

0 comments on commit 972fafb

Please sign in to comment.