This repository contains two RESTful HTTP APIs for creating and verifying accounts and passwords. The APIs are implemented in Python and packaged in a Docker container.
-
Prerequisites:
- Python 3.10.0+ (Optional)
- Docker
- Docker Compose
-
Clone the repository:
git clone https://github.com/KScaesar/senao2024.git cd senao2024
-
Run the Docker container:
APP_PORT=12450 MYSQL_PORT=3306 docker compose up -d
-
Close the Docker container:
docker compose down -v
-
Create Account API:
curl -X POST http://127.0.0.1:12450/api/v1/accounts \ -H "Content-Type: application/json" \ -d '{"username": "caesar", "password": "Senao2450"}'
-
Verify Account API:
curl -X POST http://127.0.0.1:12450/api/v1/accounts/login \ -H "Content-Type: application/json" \ -d '{"username": "caesar", "password": "Senao2450"}'
Endpoint: /api/v1/accounts
Method: POST
Request Payload:
{
"username": "caesar",
"password": "Senao2450"
}
username
: 3-32 characterspassword
: 8-32 characters, at least 1 uppercase, 1 lowercase, and 1 number
Response Payload:
{
"success": true,
"reason": ""
}
Endpoint: /api/v1/accounts/login
Method: POST
Request Payload:
{
"username": "caesar",
"password": "Senao2450"
}
Response Payload:
{
"success": false,
"reason": "Password does not match. Remaining 2 retry attempts."
}
Note: If password verification fails five times, the user must wait one minute before attempting again. The API will return an HTTP status code 429 Too Many Requests
.
負責處理與外界的交互,將外部系統、用戶接口等,連接到應用程式。
負責處理應用程式對外的 API 接口。
接收外部請求並將其轉換為應用程式可以理解的 command 或 query 。
儲存、查詢和管理資料的功能。
應用程式的主要業務規則。
pyenv install 3.10.13
pyenv virtualenv 3.10.13 senao2024
pyenv local senao2024
ln -s $(pyenv virtualenv-prefix senao2024)/envs/senao2024 .venv
pip install -r requirements.txt
pyenv install 3.10.13
pyenv local 3.10.13
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txt
DOCKER_BUILDKIT=1 docker build --build-arg BUILDKIT_INLINE_CACHE=1 -f Dockerfile -t x246libra/senaon2024:v0.1.0 .
docker push x246libra/senaon2024:v0.1.0