Skip to content

Commit 8ac391b

Browse files
authored
Merge pull request #1 from piddlingtuna/master
Merge with upstream master
2 parents 2d7dc74 + c7ec3f1 commit 8ac391b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+7194
-9444
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.env

README.md

+25-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,27 @@
11
# subcomp
2-
A project submission system for competitions.
32

4-
Originally used for the CSESoc Personal Projects Competition at [csesoc.tech](https://csesoc.tech)
3+
This is a project submission system for [CSESoc](https://csesoc.unsw.edu.au/)'s Personal Project Competition. It was written and first used in 2020 will no longer be maintained by its [original committer](https://github.com/piddlingtuna/subcomp/).
4+
5+
## Authentication
6+
7+
This project only lets users sign up using a [UNSW](https://www.unsw.edu.au/) zID. It does not hook into UNSW's authentication system, but instead verifies users by emailing their UNSW email address based on their zID. This is done when verifying users when they sign up and reseting users' password when requested.
8+
9+
## Environment variables
10+
11+
A `.env` file must exist in this directory _if you are using docker_. It must contain:
12+
13+
- `POSTGRES_USER` = the name of a user in the database. This user must have permission to read/write to the database.
14+
- `POSTGRES_PASSWORD` = the password of the above user.
15+
- `POSTGRES_DB` = the name of the database.
16+
17+
An example `.env` would look like:
18+
19+
```
20+
POSTGRES_USER=postgres
21+
POSTGRES_PASSWORD=password
22+
POSTGRES_DB=subcomp
23+
```
24+
25+
## Set Up
26+
27+
See the guide [here](set_up.md)

backend/.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
public/
21
.env
2+
public/
33

44
# Generated by Cargo
55
# will have compiled files and executables

backend/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ chrono = { version = "0.4.15", features = ["serde"] }
1010
argon2rs = "0.2.5"
1111
rocket = "0.4.5"
1212
rocket_contrib = { version = "0.4.5", features = ["json", "diesel_postgres_pool"] }
13+
rocket_cors = "0.5.1"
1314
diesel = { version = "1.4.5", features = ["postgres", "uuidv07", "chrono", "serde_json"] }
1415
dotenv = "0.15.0"
1516
serde = "1.0.115"

backend/Dockerfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ FROM rust:latest
33
WORKDIR /backend
44
COPY . .
55
RUN rustup default nightly
6-
RUN cargo build --release
76
RUN cargo install diesel_cli --no-default-features --features postgres
8-
CMD diesel setup && diesel migration run && ./target/release/backend
7+
RUN cargo build --release
8+
CMD diesel setup && ./target/release/backend

backend/README.md

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
# Backend
2+
3+
The backend server is written in Rust using the [Rocket](https://rocket.rs/) web framework and [Diesel](https://diesel.rs/) object relational mapping (ORM) and query builder.
4+
5+
The database uses [PostgreSQL](https://www.postgresql.org/). Although fancy features aren't used, it has only been tested with PostgreSQL 14.4.
6+
7+
Be a good person and run `cargo clippy --fix` every so often.
8+
9+
## Documentation
10+
11+
If you are new to Rust, take a look at the [Rust Book](https://doc.rust-lang.org/book/).
12+
13+
[See Rocket documentation.](https://rocket.rs/v0.5-rc/guide//)
14+
15+
[See Diesel documentation here.](https://diesel.rs/guides/)
16+
17+
[See PostgreSQL 14 documentation here.](https://www.postgresql.org/docs/14/index.html)
18+
19+
## Architecture
20+
21+
`src/main.rs` launches the backend server, including connecting to the database. If you add another endpoint, you will need to mount it here.
22+
23+
`src/api.rs` implements all API endpoints for the backend server, including defining the API parameters, request bodies, and response bodies. If you add another endpoint, you will need to implement it here.
24+
25+
`src/responses.rs` defines helper methods to return API responses. It is unlikely you will need to modify this file.
26+
27+
`src/handlers.rs` defines catchers to handle 4xx and 5xx errors. It is unlikely you will need to modify this file.
28+
29+
`src/models.rs` defines the database schema in the database and implements methods to select, insert, update, and delete from the database. This is where you would modify the database schema and add functions to query the database.
30+
31+
`src/schema.rs` is generated by Diesel based on `src/models.rs`. Do not modify this file.
32+
33+
`src/database.rs` implements the pool manager to the database. It is unlikely you will need to modify this file.
34+
35+
## Environment variables
36+
37+
A `.env` file must exist in this directory. It must contain:
38+
39+
- `DATABASE_URL` = A [connection URI](https://www.postgresql.org/docs/current/libpq-connect.html#LIBPQ-CONNSTRING) used by Diesel to find the database.
40+
- `PASSWORD_SALT` = [A random string used as an input when generating password bashes.](<https://en.wikipedia.org/wiki/Salt_(cryptography)>) Please use a long and complex string.
41+
- `DOMAIN` = The domain name used to host the frontend. When developing locally, this will be localhost with some port. When deploying, please use [HTTPS](https://en.wikipedia.org/wiki/HTTPS).
42+
- `SMTP_USERNAME` = An email address using [SMTP](https://en.wikipedia.org/wiki/Simple_Mail_Transfer_Protocol) under your control to send verification and password reset emails to user.
43+
- `SMTP_PASSWORD` = The password to the above email address.
44+
- `PROJECT_END` = A [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.txt) timestamp of when project submission ends.
45+
- `VOTE_END` = A [RFC 3339](https://www.rfc-editor.org/rfc/rfc3339.txt) timestamp of when voting ends.
46+
47+
An example `.env` would look like:
48+
49+
```
50+
DATABASE_URL=postgres://postgres:postgres@localhost/subcomp
51+
PASSWORD_SALT=VERY_LONG_AND_COMPLEX_STRING
52+
DOMAIN=http://localhost:3000
53+
54+
SMTP_PASSWORD=password
55+
PROJECT_END=1999-09-09T23:59:59+10:00
56+
VOTE_END=1999-09-19T23:59:59+10:00
57+
```

backend/Rocket.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[production]
2+
address = "0.0.0.0"

backend/migrations/2020-09-07-091403_auth/up.sql

+5-5
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ CREATE TABLE projects (
88
summary TEXT NOT NULL,
99
link TEXT NOT NULL,
1010
repo TEXT NOT NULL,
11-
first_year BOOLEAN DEFAULT FALSE NOT NULL,
12-
postgraduate BOOLEAN DEFAULT FALSE NOT NULL
11+
firstyear BOOLEAN DEFAULT FALSE NOT NULL,
12+
postgrad BOOLEAN DEFAULT FALSE NOT NULL
1313
);
1414

1515
SELECT diesel_manage_updated_at('projects');
@@ -19,7 +19,7 @@ CREATE TABLE users (
1919
created_at TIMESTAMP DEFAULT current_timestamp NOT NULL,
2020
updated_at TIMESTAMP DEFAULT current_timestamp NOT NULL,
2121
zid CHAR(8) UNIQUE NOT NULL,
22-
full_name TEXT NOT NULL,
22+
name TEXT NOT NULL,
2323
password_hash BYTEA NOT NULL,
2424
project_id UUID DEFAULT NULL references projects(id)
2525
);
@@ -43,8 +43,8 @@ CREATE TABLE verifications (
4343
created_at TIMESTAMP DEFAULT current_timestamp NOT NULL,
4444
updated_at TIMESTAMP DEFAULT current_timestamp NOT NULL,
4545
token CHAR(32) UNIQUE NOT NULL,
46-
zid CHAR(8) NOT NULL,
47-
full_name TEXT NOT NULL,
46+
zID CHAR(8) NOT NULL,
47+
name TEXT NOT NULL,
4848
password_hash BYTEA NOT NULL
4949
);
5050

0 commit comments

Comments
 (0)