Skip to content

Commit

Permalink
First user becomes admin, add more instructions
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanlaj committed Apr 27, 2024
1 parent babb666 commit bb4f0a5
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# use this for production / hosting your own app

DB_ROOT_PWD=""
ACCESS_TOKEN_SECRET=""
REFRESH_TOKEN_SECRET=""
DB_ROOT_PWD="" # The root password for the database
ACCESS_TOKEN_SECRET="" # The secret for the access token used for logins
REFRESH_TOKEN_SECRET="" # The secret for the refresh token used for logins
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,29 @@ Capture the Feather is a capture the flag platform that will focus on the learni

As a capture the flag platform, users will be able to sign up for the platform and try to complete cybersecurtity challenges created by an administrator. These challenges could range from simple web challenges to reverse engineering challenges. Users and admin will be able to keep track of who completes challenges the quickest and who has the most points.

## Hosting Instructions

1. Clone the repository
1. Copy the `.env.example` file in the root directory to a new file called `.env`
1. Fill in the `.env` file with the appropriate values.
1. Run `docker-compose up` in the root directory. This will start the database, backend, and frontend.
1. Go to `http://localhost:3000` in your browser to view the frontend.
1. Click on the `Register` button on the top right to create an account. The first account created will be an admin account.
1. If you need to import challenges from another source, such as [here](https://github.com/csivitu/ctf-challenges/tree/master), see the README in the `importer` directory.

## Development Setup Instructions

1. Clone the repository
1. Run `npm install` in the root directory.
1. Copy the `.env.example` file in the root directory to a new file called `.env`
1. Fill in the `.env` file with the appropriate values.
1. Run `docker-compose up -d db` in the root directory. This will start the database.
1. Navigate into the `server` directory.
1. Run `npm install` in the `server` directory.
1. Navigate back to the root directory and then into the `client` directory.
1. Run `npm install` in the `client` directory.
1. Navigate back to the root directory and run `npm run dev` to start the backend and frontend.

## Timeline of Completion

_For each milestone, I will add some unit tests to backend code only as it will contain the most logic._
Expand Down
2 changes: 1 addition & 1 deletion importer/.env.example
Original file line number Diff line number Diff line change
@@ -1 +1 @@
CTF_DB_URL=""
CTF_DB_URL="mysql://root:${DB_ROOT_PWD}@localhost:3306/capture-the-feather"
11 changes: 11 additions & 0 deletions importer/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# How to Import Challenges

This project is used to import challenges from .yml files into the database. The .yml files should be in the same format as the ones in the `supported` directory.

A good example of where to find such challenges is [here](https://github.com/csivitu/ctf-challenges/tree/master). Dockerfile challenges are not supported at this time.

1. Copy the `.env.example` file in the root directory to a new file called `.env`
1. Fill in the `.env` file with the appropriate values.
1. Run `npm install` in the root directory.
1. Copy the challenges you want to import into a new folder in the `importer` project. The import script will look for all files named 'challenge.yml' and attempt to import them.
1. Run `npm run import` in the root directory. Follow the prompts to import the challenges.
2 changes: 1 addition & 1 deletion server/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Use this for development purposes only

CTF_DB_URL=""
CTF_DB_URL="mysql://root:${DB_ROOT_PWD}@localhost:3306/capture-the-feather"
ACCESS_TOKEN_SECRET=""
REFRESH_TOKEN_SECRET=""
3 changes: 3 additions & 0 deletions server/src/controllers/me.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,15 @@ router.post("/register", requireBody(['email', 'name', 'password']), errorHandle
return;
}

const isFirstUser = await User.count() === 0;

const hashedPassword = await hashPassword(password);

const newUser = await User.create({
email,
name,
passwordHash: hashedPassword,
isAdmin: isFirstUser,
});

const tokens = await generateTokens(newUser.id, newUser.isAdmin);
Expand Down

0 comments on commit bb4f0a5

Please sign in to comment.