Skip to content
This repository was archived by the owner on Sep 8, 2019. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
80 commits
Select commit Hold shift + click to select a range
900378d
Added README.md
thurstonian Feb 4, 2019
8a8f13f
Fixed formatting on headers
thurstonian Feb 4, 2019
d0ad4fa
Changed header formatting
thurstonian Feb 4, 2019
9faf1ba
Changed header formatting
thurstonian Feb 5, 2019
409a626
Backend Readme Initial Push
thurstonian Feb 5, 2019
b2b7c9a
Merge branch 'initial-docs' of https://github.com/Rowan-ECE-Resource-…
thurstonian Feb 5, 2019
d3828dd
Test form for AJAX calls
thurstonian Feb 5, 2019
e963b00
Merge pull request #1 from Rowan-ECE-Resource-Center/initial-docs
thurstonian Feb 5, 2019
19b82d7
Update README.md
thurstonian Feb 5, 2019
1dff388
Merge remote-tracking branch 'origin/master'
timothyhollabaugh Feb 8, 2019
64844ff
Added a user import from csv.
Feb 11, 2019
2602177
Cleaned up and commented csv_user_import.
Feb 11, 2019
8c3b936
Deleted Duplicate Files
kluzynskn6 Feb 12, 2019
4f37f4e
Cleaned csv_import and renamed it.
Feb 12, 2019
bd47a23
Merge branch 'master' of https://github.com/kluzynskn6/main-server
Feb 12, 2019
216673e
Merge pull request #2 from kluzynskn6/master
timothyhollabaugh Feb 13, 2019
dbdcb41
Added very basic search.
Feb 15, 2019
1e48693
Better user searching
timothyhollabaugh Feb 16, 2019
bddc8ea
Search can do partial or exact
timothyhollabaugh Feb 16, 2019
175c199
Merge remote-tracking branch 'upstream/search' into search
timothyhollabaugh Feb 16, 2019
9331f51
Add files via upload
amorye7 Feb 19, 2019
2bb2057
Can now add, edit, and remove from users
Feb 21, 2019
476aa80
Moved Mockups to folder
amorye7 Feb 22, 2019
acda28e
Fixed static IP problem
Feb 22, 2019
20de24d
Merge remote-tracking branch 'nick/master' into upstream_dev
timothyhollabaugh Feb 25, 2019
480c3c4
Moved to correct folder
amorye7 Feb 26, 2019
ea5586e
Moved mockups to folders
amorye7 Feb 26, 2019
6cb6faf
Add files via upload
amorye7 Feb 26, 2019
d8b8f57
Moved PNG files to correct folder
amorye7 Feb 26, 2019
33a58b6
Add files via upload
amorye7 Feb 26, 2019
f4b2af6
Add files via upload
amorye7 Feb 26, 2019
58c28f3
Delete incorrect files
amorye7 Feb 26, 2019
c9f5323
Deleted wrong files
amorye7 Feb 26, 2019
edea4bf
Add files via upload
amorye7 Feb 26, 2019
4a4dcd7
Add files via upload
amorye7 Feb 26, 2019
9a3f96b
Merge remote-tracking branch 'lizzie/master' into upstream_dev
timothyhollabaugh Feb 27, 2019
5bb0f4e
Added header and styling
Feb 28, 2019
29ed584
Add Database_Relationship_Diagram
timothyhollabaugh Mar 1, 2019
42eb196
Change logging to SimpleLogger so it works in docker
timothyhollabaugh Mar 1, 2019
46722c7
Retry connecting to the database if it fails
timothyhollabaugh Mar 1, 2019
77e3eea
docker compose to start backend and mysql.
timothyhollabaugh Mar 1, 2019
5fd6e17
Run migrations when the server starts
timothyhollabaugh Mar 2, 2019
ca5db2f
Add dockerfile for frontend
timothyhollabaugh Mar 2, 2019
d9ab397
Remove volume from mysql. No longer needed
timothyhollabaugh Mar 2, 2019
68a822c
Merge remote-tracking branch 'nick/master' into docker
timothyhollabaugh Mar 2, 2019
f95cfa0
Include .html in all links
timothyhollabaugh Mar 2, 2019
a53faad
Add frontend to docker compose
timothyhollabaugh Mar 2, 2019
7fa4909
Remove :8000 from all ajax calls
timothyhollabaugh Mar 2, 2019
b5c98fe
Apache redirects /api/v1 to the backend
timothyhollabaugh Mar 2, 2019
013d701
Remove yet another :8000
timothyhollabaugh Mar 2, 2019
e55255c
Merge pull request #6 from timothyhollabaugh/docker
timothyhollabaugh Mar 2, 2019
ee8edb2
Initial framework for permissions system.
penatem1 Mar 9, 2019
182e27f
Initial framework for permissions system.
penatem1 Mar 9, 2019
734a530
Implemented http methods for authorization systems commands.
penatem1 Mar 13, 2019
a5edf93
Implemented http methods for authorization systems commands.
penatem1 Mar 13, 2019
1d940ca
Bug fixes and general optimizations in authorization systems.
penatem1 Mar 13, 2019
1e834f3
Bug fixes and general optimizations in authorization systems.
penatem1 Mar 13, 2019
e6ce81e
Brought project back to original layout. Fixed user_access search.
penatem1 Mar 26, 2019
ea07c94
Brought project back to original layout. Fixed user_access search.
penatem1 Mar 26, 2019
7ee6596
Switch back to SERIAL. (u64 support)
penatem1 Mar 26, 2019
425d26e
Switch back to SERIAL. (u64 support)
penatem1 Mar 26, 2019
4600a54
Auth branch commit
penatem1 Apr 15, 2019
55847cf
Implemented chemicals backend.
penatem1 Apr 15, 2019
19a5e6c
Implemented more fields for chemicals and chemical_inventory. Bug fixes
penatem1 Apr 15, 2019
b111454
Add semicolons to the end of migration sql commands
timothyhollabaugh Apr 16, 2019
e4cc0e8
Log a warning if migrations failed
timothyhollabaugh Apr 16, 2019
1066add
cargo fmt the backend
timothyhollabaugh Apr 16, 2019
02f4b36
Add Option to Partial fields
timothyhollabaugh Apr 16, 2019
06821cc
Merge pull request #1 from timothyhollabaugh/chemical
penatem1 Apr 16, 2019
7c35240
SD removal
penatem1 Apr 16, 2019
b425987
Merge branch 'auth' of https://github.com/penatem1/main-server into auth
penatem1 Apr 16, 2019
c9ef9d5
SDR
penatem1 Apr 16, 2019
cc20ecb
Order of operations bug fix.
penatem1 Apr 16, 2019
87a6136
Merge branch 'master' into chemical
penatem1 Apr 19, 2019
ca4e6f8
Merge pull request #3 from penatem1/chemical
penatem1 Apr 19, 2019
5923496
Cargo format, fixes, prep for merge.
penatem1 Apr 19, 2019
891dbb4
Merge branch 'master' into auth
penatem1 Apr 19, 2019
1be0b76
Merge pull request #4 from penatem1/auth
penatem1 Apr 19, 2019
e57c7e5
Added authorization to chemical(_inventory) Merge fixes, Cargo fmt.
penatem1 Apr 20, 2019
f525366
Updated readme for backend, pushed signin functions JS file.
penatem1 Apr 20, 2019
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
127 changes: 127 additions & 0 deletions backend/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions backend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ edition = "2018"

[dependencies]
rouille = "3.0.0"
google-signin = "0.3.0"
diesel = { version = "1.3.3", features = ["mysql"] }
diesel_migrations = "1.4.0"
dotenv = "0.13.0"
Expand Down
31 changes: 31 additions & 0 deletions backend/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,43 @@ Coded in Rust, manages database manipulation using AJAX requests from frontend.
### Dependencies:
* [Rouille 3.0.0](https://github.com/tomaka/rouille)
* [Diesel 1.3.3](https://github.com/diesel-rs/diesel)
* [Google Sign-In 0.3.0](https://github.com/wyyerd/google-signin-rs)
* [dotenv 0.13.0](https://github.com/sgrif/rust-dotenv)
* [serde 1.0](https://github.com/serde-rs/serde)
* [serde_json 1.0](https://github.com/serde-rs/json)
* [log 0.4](https://github.com/rust-lang-nursery/log)
* [simplelog](https://github.com/drakulix/simplelog.rs)

### Authentication and Authorization

#### Authentication and Authorization Flow
1. On the frontend, a sign-in button that redirects to Google sign-in calls `onSignIn()` afterwards to set a cookie for the `id_token` of the logged in user.
* That cookie has an expire date, and will delete itself from the browser once that date has passed.
* If a user on the frontend prompts an action that attempts to access the `id_token` cookie and it is not present, a login is automatically prompted.
2. The frontend generates an xmlHTTP request over HTTPS with `id_token` in the header.
* Sending the ID token over HTTP exposes the user's token to packet sniffing vulnerabilities, allowing sniffers to impersonate the user by submitting unauthentic requests with the unencrypted token.
3. The backend attempts authentication before processing the requests (some requests might need authorization, some might not).
* The token is sent back to Google's servers with our services information, Google does their own verification and sends back valid user data.
4. The email is taken from the Google user's data and cross checked with the `users` database.
* NOTE: AN EMAIL IS NECESSARY FOR AUTHORIZED REQUESTS
5. The request is processed and just before execution of the request, the backend checks for authorization on the found user if needed.
* A `user_access` request is made to verify authorization

#### Making Authorized API Calls

To make an authorized API call, a valid ID token from Google's sign-in services must be present in the HTTPS request.

Add the following script imports to HTML pages that make requests.

`<script src="https://apis.google.com/js/platform.js" async defer></script>`

`<script type="text/javascript" src="/access/google_signin.js"></script>`


And add the following to JavaScript functions that make xmlHTTP requests

`mlhttp.setRequestHeader("id_token", getID_Token());`

### API Calls

`GET /users`
Expand Down
2 changes: 1 addition & 1 deletion backend/diesel.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# see diesel.rs/guides/configuring-diesel-cli

[print_schema]
file = "src/schema.rs
file = "src/schema.rs"
2 changes: 1 addition & 1 deletion backend/migrations/2019-01-13-203149_create_users/down.sql
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
-- This file should undo anything in `up.sql`
DROP TABLE users
DROP TABLE users;
9 changes: 8 additions & 1 deletion backend/migrations/2019-01-13-203149_create_users/up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,11 @@ CREATE TABLE users (
last_name VARCHAR(255) NOT NULL,
banner_id INT(9) UNSIGNED NOT NULL,
email VARCHAR(255)
)
);

INSERT INTO users (first_name, last_name, banner_id) VALUES ("root", "root", 0);
UPDATE users
SET
id = 0
WHERE
first_name="root" AND last_name="root" AND banner_id=0 AND id != 0;
3 changes: 3 additions & 0 deletions backend/migrations/2019-03-08-171503_create_access/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
DROP TABLE user_access;
DROP TABLE access;
53 changes: 53 additions & 0 deletions backend/migrations/2019-03-08-171503_create_access/up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
-- Your SQL goes here
CREATE TABLE access (
id SERIAL PRIMARY KEY,
access_name VARCHAR(255) NOT NULL
);

INSERT INTO access (access_name) VALUES
("RootAccess"),

("GetUsers"),
("CreateUsers"),
("UpdateUsers"),
("DeleteUsers"),

("GetAccess"),
("CreateAccess"),
("UpdateAccess"),
("DeleteAccess"),

("GetUserAccess"),
("CreateUserAccess"),
("UpdateUserAccess"),
("DeleteUserAccess"),

("GetChemical"),
("CreateChemical"),
("UpdateChemical"),
("DeleteChemical"),

("GetChemicalInventory"),
("CreateChemicalInventory"),
("UpdateChemicalInventory"),
("DeleteChemicalInventory");

CREATE TABLE user_access (
permission_id SERIAL PRIMARY KEY,
access_id BIGINT UNSIGNED NOT NULL,
user_id BIGINT UNSIGNED NOT NULL,
FOREIGN KEY (access_id)
REFERENCES access(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
FOREIGN KEY (user_id)
REFERENCES users(id)
ON DELETE CASCADE
ON UPDATE CASCADE,
permission_level VARCHAR(255)
);

INSERT INTO user_access(access_id, user_id, permission_level)
SELECT (select access.id as access_id from access where access.name = "RootAccess"),
(select users.id as user_id from users where user.id = 0),
(select "RootAccess" as permission_level);
3 changes: 3 additions & 0 deletions backend/migrations/2019-04-15-150025_chemicals/down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- This file should undo anything in `up.sql`
DROP chemical_inventory;
DROP chemical;
Loading