This is a open source and selfhosted fitness challenges server, which allows users to create and manage and share fitness challenges with friends. Users can be created via environment variables in the Docker configuration or through a command-line interface (CLI) (There is no registration currently). The server provides various endpoints for user authentication and challenge management, enabling users to create, share, and delete challenges while tracking their progress through recorded activities.
User Creation
- Create users using environment variables (limited to 20 users, for testing only).
- Create users via CLI commands.
Authentication
- Obtain JWT tokens for secure user authentication.
Challenge Management (with UI)
- Create new challenges.
- List challenges created by the user.
- List challenges shared with the user.
- View specific challenges by ID.
- List challenges shared from other users.
- Share challenges with other users via email.
- Delete challenges by ID.
- Insert challenge records to track activities (e.g., distance, type).
- Show challenge records, including those shared with the user.
NOTE: currently development only, ports need to be closed and passwords/secrets changed in production env. Use at your own risk!!!
# build
docker build -t postgres-challenges:local -f db-postgres/Dockerfile-postgres db-postgres
# start
docker compose up -d
# logs
docker compose logs -f
docker exec -it db_challenges bash add-user.sh username="[email protected]" password="securepassword"
(not recommended, for testing only, max 20 users limit)
db_challenges:
environment:
... all the other variables()
USER1_EMAIL: "[email protected]"
USER1_PASSWORD: securepassword
- open Browser on
http://localhost:81
- enter for
URL
default valuehttp://localhost:3000
(your postgREST server port) - default user:
[email protected]
- default pass:
securepassword
docker exec -it db_challenges psql -U challenges_user challenges
TOKEN=$(curl -X POST "http://localhost:3000/rpc/login" \
-H "Content-Type: application/json" \
-d '{ "email": "[email protected]", "pass": "securepassword" }' | jq -r .token)
# Debugging the token
echo "Using token: $TOKEN"
curl http://localhost:3000/challenge_list -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Test Challenge",
"from": "2024-10-20",
"to": "2024-11-20",
"type": "running"
}'
curl http://localhost:3000/challenge_list \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl http://localhost:3000/user_challenges \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl http://localhost:3000/challenge_list\?challenge_id\=eq.1 \
-H "Authorization: Bearer $TOKEN"
curl http://localhost:3000/shared_challenges \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl http://localhost:3000/challenge_shares -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"challenge_id": "1",
"shared_with": "[email protected]"}'
curl http://localhost:3000/challenge_list\?challenge_id\=eq.1 -X DELETE \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
curl http://localhost:3000/challenge_records -X POST \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"challenge_id": 2,
"timestamp": 1698019200,
"type": "running",
"distance": 11.5
}'
curl http://localhost:3000/shared_challenge_records \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json"
# Allow "tr" to process non-utf8 byte sequences
export LC_CTYPE=C
# Read random bytes keeping only alphanumerics and add the secret to the configuration file
echo "jwt-secret = \"$(< /dev/urandom tr -dc A-Za-z0-9 | head -c32)\"" >> tutorial.conf
curl -X POST "http://localhost:3000/rpc/login" \
-H "Content-Type: application/json" \
-d '{ "email": "[email protected]", "pass": "securepassword" }'