Skip to content

Commit

Permalink
Merge pull request #12 from CEN3031-SIT-WEB-APP/CEN3031-dev
Browse files Browse the repository at this point in the history
Cen3031 dev
  • Loading branch information
christian-marin authored Apr 12, 2018
2 parents d00773b + 06159de commit 7aa7ef8
Show file tree
Hide file tree
Showing 191 changed files with 24,038 additions and 10,007 deletions.
63 changes: 63 additions & 0 deletions .angular-cli.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "ufInfoSec_webapp"
},
"apps": [
{
"root": "src",
"outDir": "static",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"assets/css/bootstrap.min.css",
"assets/css/bootstrap-grid.min.css",
"assets/css/github-markdown.css",
"styles.css"
],
"scripts": [],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}
],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [
{
"project": "src/tsconfig.app.json",
"exclude": "**/node_modules/**"
},
{
"project": "src/tsconfig.spec.json",
"exclude": "**/node_modules/**"
},
{
"project": "e2e/tsconfig.e2e.json",
"exclude": "**/node_modules/**"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
10 changes: 8 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,17 @@
.env

# Potentially Sensitive
*.json
credentials.json

# Vim shit
# Vim
*.swp
*.swo

# Bulky. Prefer dynamic resolution
node_modules/

# angular optimized build
static/

# Misc
aws.json
124 changes: 85 additions & 39 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,25 @@ Create this file in the same directory as `app.js` and name it `credentials.json
Note that this provided file assumes you are using the default `root` user without a password and with a database
name of `ufsit_portal`. This may be different depending on your MySQL setup.

With this file, you can run the node application using:
We must also create a file to store the Amazon S3 credentials to tell the webapp how to communicate with AWS. Here is an example file

```json
{
"region":"us-east-1",
"accessKeyId":"",
"secretAccessKey":"",
"s3Bucket":""
}
```

With this file, you can start the server with:

```
node app.js
node run dev
```
Note: This will run both the nodeJS server and the angular server. Both will automatically reload when any of their files are modified.

Or with NPM like:
To create a production build of the frontend and start the nodeJS server to deploy them, run:

```
npm start
Expand All @@ -78,20 +90,21 @@ If you have multiple database credentials files (e.g. one for development and an
explicitly pass the filename in an environment variable:

```shell
CREDENTIALS=credentials.json node app.js
CREDENTIALS=credentials.json AWS=aws.json node app.js
```

Where the `CREDENTIALS` environment variable points to the details about the database you are connecting to.
This variable can be exported or passed on the command line right before the start command.
Where the `CREDENTIALS` environment variable points to the details about the database you are connecting to, and `AWS` environment variable points to the Amazon S3 credentials.
These variables can be exported or passed on the command line right before the start command.

If this environment variable is not included, the application will fallback to a file named `credentials.json` or a
If the `CREDENTIALS` environment variable is not included, the application will fallback to a file named `credentials.json` or a
Heroku specific environment variable for our JawsDB plan. The JawsDB
variable _only_ exists when running in the Heroku cloud, so the webapp will
error out if it was not able to find valid credentials for the database.
error out if it was not able to find valid credentials for the database.
If the `AWS` environmental variable is not included, the application will fallback to a file name aws.json.

## Starting Development

With the webapp running locally, you can visit http://localhost:8080 in your web browser.
With the webapp running locally, you can visit http://localhost:4200 in your web browser.
Here you can modify any file on both the server-side and client side. It is **strongly recommended**
that you use [nodemon](https://github.com/remy/nodemon) to automatically restart the node
process when a server file is changed. This will save you from development headaches.
Expand All @@ -102,54 +115,87 @@ you may run `nodemon app.js` instead of `node app.js` or `npm start`.
### Code Map
The top-level file is `app.js`. This configures Express the site in general. The API directory has the actual routes along with the DB-related helper functions in the `db/` directory. Knowledge of Express should not extend down to the DB directory and should only be handled at the top-level route declarations.

For the front end, the `html/` directory has all of the Angular-based HTML, `css/` all of the stylesheets, `scripts/controller/` all of the NG controllers, `images/` all of the images, and `routes/config.js` the top-level single-page application routing configuration.
For the front end, the `src/` directory has all of the Angular-based code. Within `src/`, `app/` contains the components that make up the application, and `assets/` contains other necessary files, such as images and stylesheets. Each component within `app/` has its own stylesheet, html, typescript, and unit testing file. Also contained in `app/` are services and the routing module.

```
├── API/
│   ├── README.md
├── api
│   ├── admin.js
│   ├── anonymous.js
│   ├── db/
│   ├── db
│   │   ├── account_mgmt.js
│   │   ├── admin.js
│   │   ├── db_mgmt.js
│   │   └── event_mgmt.js
│   ├── event.js
│   ├── index.js
│   ├── README.md
│   ├── session.js
│   └── user.js
│   ├── upload.js
│   ├── user.js
│   └── writeups.js
├── app.js
├── css/
│   ├── bootstrap.css
│   └── ...
├── data/
│   └── schema.sql
├── html/
├── aws.json
├── credentials.json
├── nodemon.json
├── package.json
├── package-lock.json
├── proxy.conf.json
├── README.md
├── src
│   ├── app
│   │   ├── about
│   │   │   ├── about.component.css
│   │   │   ├── about.component.html
│   │   │   ├── about.component.spec.ts
│   │   │   └── about.component.ts
│   │   ├── admin
│   │   │   ├── admin.component.css
│   │   │   ├── ...
│   │   ├── app.component.css
│   │   ├── app.component.html
│   │   ├── app.component.spec.ts
│   │   ├── app.component.ts
│   │   ├── app.module.ts
│   │   ├── app-routing.module.ts
│   │   ├── ...
│   ├── assets
│   │   ├── calendar-alt.svg
│   │   ├── css
│   │   │   ├── bootstrap-grid.min.css
│   │   │   ├── ...
│   │   ├── images
│   │   │   ├── Chabab.png
│   │   │   ├── ...
│   │   ├── list-alt.svg
│   │   ├── sit.png
│   │   └── sponsors
│   │   ├── CSFSU.png
│   │   ├── ...
│   ├── environments
│   │   ├── environment.prod.ts
│   │   └── environment.ts
│   ├── favicon.ico
│   ├── index.html
│   ├── login.html
│   ├── main.ts
│   ├── polyfills.ts
│   ├── styles.css
│   ├── test.ts
│   ├── tsconfig.app.json
│   ├── tsconfig.spec.json
│   └── typings.d.ts
├── static_old
│   ├── css
│   │   ├── bootstrap.css
│   │   ├── ...
│   ├── views
│   │   ├── admin.html
│   ├── ...
│   └── views/
│   ├── header.html
│   ├── home.html
│   └── ...
├── images/
│   └── ...
├── package.json
├── routes/
│   └── config.js
├── scripts/
│   └── controllers/
│   ├── AdminController.js
│   ├── LoginController.js
│   └── ...
├── services/
│   └── Validate.js
└── util/
└── util
└── index.js
```

### Relevant Documentation
* AngularJS 1.x - https://docs.angularjs.org/guide
* AngularJS 5.x - https://angular.io/docs/
* Node.js Express - https://expressjs.com/en/4x/api.html
* Node.sj 9.3.x - https://nodejs.org/dist/latest-v9.x/docs/api/
* MySQL for Node.js - https://www.npmjs.com/package/mysql
Expand Down
41 changes: 32 additions & 9 deletions api/admin.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,40 @@
'use strict';

const routes = require('express').Router(); // eslint-disable-line new-cap
const admin_mgmt = require('./db/admin_mgmt.js'); // App-specific module imports
const util = require.main.require('./util');

/* App-specific module imports */
const admin = require('./db/admin.js');

routes.get('/admin/list_users', async (req, res, next) => {
if (util.account_has_admin(req.account)) {
res.status(200).json(await admin.list_users());
} else {
res.status(403).send('Access denied');
}
if (util.account_has_admin(req.account)) {
return res.status(200).json(await admin_mgmt.list_users());
} else {
return res.status(403).send('Access denied');
}
});

routes.post('/admin/add_tile', async (req, res, next) => {
if (util.account_has_admin(req.account)) {
try {
await admin_mgmt.add_tile(
req.body.name,
req.body.description,
req.body.link
);
res.status(200).send('Success');
} catch (error) { return next(error) }
} else {
res.status(403).send('Access denied');
}
});

routes.post('/admin/delete_tile', async (req, res, next) => {
if (util.account_has_admin(req.account)) {
try {
await admin_mgmt.delete_tile(req.body.id);
res.status(200).send('Success');
} catch (error) { return next(error) }
} else {
res.status(403).send('Access denied');
}
});

module.exports = routes;
Loading

0 comments on commit 7aa7ef8

Please sign in to comment.