4.1 KiB
Interbend API
Interbend is a Flask-based web application that provides a backend API for managing user balances and transactions. It features a robust authentication system using JWT and includes a separate set of administrative endpoints for system management. The application is designed to be extensible and can be used as a foundation for a variety of financial applications.
Note
The GitHub branch may lag behind the development branch. For the most up-to-date code and pull requests, please visit https://git.albioncloud.de/Eisbear/Interbend.
Installation
-
Clone the repository:
git clone https://github.com/your-username/interbend.git cd interbend -
Create a virtual environment and activate it:
python3 -m venv venv source venv/bin/activate -
Install the dependencies:
pip install Flask python-dotenv mysql-connector-python PyJWT -
Set up the environment variables: Create a
.envfile in the root directory of the project and add the following variables:JWT_KEY=your_secret_jwt_key JWT_EXPIRATION=30 // jwt experation duration in days DB_HOST=your_database_host DB_USER=your_database_user DB_PASSWORD=your_database_password DB_NAME=your_database_name ADMIN_KEY=your_secret_admin_key COLLECT_COOLDOWN=24 // collect cooldown in hours TAX_ACCOUNT_BID=BUSINESS_BID_HERE // tax account bid here
Usage
To start the application, run the following command in the root directory of the project:
python run.py
The application will start in debug mode on http://127.0.0.1:5000.
API Endpoints
Authentication
-
POST /register: Creates a new user account.- Request Body:
{ "username": "testuser", "email": "test@example.com", "password": "password123" } - Response: Sets a JWT token in an HTTP-only cookie and returns a success message.
- Request Body:
-
POST /login: Logs in a user.- Request Body:
{ "bid": "your_user_bid", "password": "password123" } - Response: Sets a JWT token in an HTTP-only cookie and returns a success message.
- Request Body:
Transactions
-
GET /balance?bid=<user_bid>: Retrieves the balance of a user.- Response:
{ "balance": 100.00 }
- Response:
-
POST /collect: Collects the salary for the authenticated user.- Authentication: JWT token required.
- Response: A success message and the new balance.
-
POST /transfer: Transfers a specified amount from the authenticated user to another user.- Authentication: JWT token required.
- Request Body:
{ "to": "recipient_bid", "amount": 50.00, "note": "Payment for services" } - Response: A success message.
-
POST /transfer-business: Transfers a specified amount from the authenticated user to another user with an appled tax.- Authentication: JWT token required.
- Request Body:
{ "to": "recipient_bid", "amount": 50.00, "note": "Payment for services" } - Response: A success message.
Admin
All admin endpoints require an admin key in the request body.
-
POST /admin/set-job: Sets the job for a user.- Request Body:
{ "bid": "user_bid", "job": 1, "key": "your_admin_key" } - Response: A success message.
- Request Body:
-
POST /admin/add-money: Adds money to a user's account.- Request Body:
{ "bid": "user_bid", "amount": 100.00, "key": "your_admin_key" } - Response: A success message.
- Request Body:
-
POST /admin/change-password: Changes the password for a user.- Request Body:
{ "bid": "user_bid", "password": "new_password", "key": "your_admin_key" } - Response: A success message.
- Request Body:
Bot
All bot endpoints require a bot key in the request body. These endpoints are designed with the InterBot discordbot in mind. You should never use these manually because they trust the discord bot for authentication and are therefore insecure. (i dont think thats best practice?) // TODO - Add Discord End Points here /