Skip to content

Commit

Permalink
feat: adds homemade mail confirmation and removes external library (#77)
Browse files Browse the repository at this point in the history
* feat: adds homemade mail confirmation and removes external library

but it also adds another library to handle non-blocking mail sending.

* chore: suggestion from review

* feat: new exception handler and common error response

* chore: suggestion from review

* chore: remove hardcoded links from the code and add them to example.env

* feat: add root page with a simple health check

* chore: update readme file to include the API collection folder

* chore: add the new reset password endpoints to API collection

* chore: documentation of endpoints and general cleanup
  • Loading branch information
corp-0 authored Feb 7, 2024
1 parent 49e44c6 commit b13e844
Show file tree
Hide file tree
Showing 32 changed files with 891 additions and 288 deletions.
7 changes: 5 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ ENV PYTHONUNBUFFERED=yes \

WORKDIR /src

COPY poetry.lock pyproject.toml .
COPY poetry.lock pyproject.toml ./

RUN : \
# psycopg runtime dep
Expand All @@ -36,12 +36,15 @@ COPY src .
RUN : \
&& mkdir /home/website \
&& mkdir /home/website/statics \
&& mkdir /home/website/media
&& mkdir /home/website/media \
&& mkdir /home/website/logs

# removes \r from script and makes it executable.
# both of these are caused by windows users touching file and not configuring git properly
RUN : \
&& sed -i 's/\r//g' entrypoint.sh \
&& chmod +x entrypoint.sh

RUN crontab -l | { cat; echo "* * * * * python /src/manage.py send_queued_mail >> /home/website/logs/send_mail.log 2>&1"; } | crontab -

ENTRYPOINT ["./entrypoint.sh"]
40 changes: 24 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,21 @@ The all-in-one backend application for [Unitystation](https://github.com/unityst

## Development guide

### Settings file
#### pre-commit

pre-commit is a git hook which runs every time you make a commit to catch linting and formatting errors early.

```sh
pre-commit install
```

> Hint: if the world is on fire, production servers down, clown at your doorstep and you don't have time to make linters happy, add `-n` to `git commit` command (CI will still be mad though).
Copy `example.env` to `.env` and customize it.
### Environment setup

### Setting up python
Copy `example.env` to `.env` and customize it. You can then start development by either using docker or running the project locally.

### Setting up python to run the project locally

You will need python 3.11+

Expand Down Expand Up @@ -60,16 +70,13 @@ Install dev dependencies
poetry install
```

#### pre-commit

pre-commit is a git hook which runs every time you make a commit to catch linting and formatting errors early.
#### Start the server

from the src folder run
```sh
pre-commit install
python manage.py runserver
```

> Hint: if the world is on fire, production servers down, clown at your doorstep and you don't have time to make linters happy, add `-n` to `git commit` command (CI will still be mad though).
### Setting up Docker

Docker (with help of compose) lets you launch entire project including database locally without installing anything.
Expand All @@ -78,14 +85,15 @@ Docker (with help of compose) lets you launch entire project including database

2- Launch project by running `docker compose -f dev-compose.yml up --build`.

3- Test out the webui by accessing http://localhost:8000/

### Navigating web UI
### Try it out

Assuming you've managed to get a page running on http://localhost:8000/, we can now start doing things such as registering a test account.
After everything is done, you can access the web UI at http://localhost:8000/. Here you will see the automatic documentation for the API and you can test out the API end points.

Some other useful links:
- http://localhost:8000/admin -> View all accounts and edit existing ones.
- http://localhost:8000/accounts/register -> Create an account (if you already don't have one)
- http://localhost:8000/accounts/verify-account -> Test account verfication manually.
- http://localhost:8000/accounts/register -> Create an account.
- http://localhost:8000/accounts/login-credentials -> Test loging in with a username and password.
- http://localhost:8000/accounts/login-token -> Test loging in with a token (see admin page if you lost the token after login with credentials).

To find more api end points or add new ones, check out `urls.py` under the respective folder of what feature you want mess around with.
You can also use [Bruno](https://www.usebruno.com/) (a Postman alternative) to test out the API.
The Bruno project is included in the repository and you can find it in the 'api-collection' folder in the root of the repository.
11 changes: 11 additions & 0 deletions api-collection/Auth/Mail confirmation/ConfirmAccount.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta {
name: ConfirmAccount
type: http
seq: 1
}

post {
url: {{baseUrl}}/accounts/confirm-account/<token you get via email here>
body: none
auth: none
}
17 changes: 17 additions & 0 deletions api-collection/Auth/Mail confirmation/Resend mail confirmation.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
meta {
name: Resend mail confirmation
type: http
seq: 2
}

post {
url: {{baseUrl}}/accounts/resend-account-confirmation
body: json
auth: none
}

body:json {
{
"email": "mail@mail.com"
}
}
17 changes: 17 additions & 0 deletions api-collection/Auth/ResetPassword/confirm the reset.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
meta {
name: confirm the reset
type: http
seq: 2
}

post {
url: {{baseUrl}}/accounts/reset-password/<token here>
body: json
auth: none
}

body:json {
{
"password": "admin"
}
}
17 changes: 17 additions & 0 deletions api-collection/Auth/ResetPassword/request a reset.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
meta {
name: request a reset
type: http
seq: 1
}

post {
url: {{baseUrl}}/accounts/reset-password/
body: json
auth: none
}

body:json {
{
"email": "admin@admin.com"
}
}
5 changes: 5 additions & 0 deletions example.env
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,8 @@ DB_ENGINE=django.db.backends.postgresql
DB_NAME=postgres
DB_HOST=db
DB_PORT=5432

# Links to stuff
WEBSITE_URL = http://localhost:8000
PASS_RESET_URL_SUFFIX = reset-password/
ACCOUNT_CONFIRMATION_URL_SUFFIX = confirm-email/
Loading

0 comments on commit b13e844

Please sign in to comment.