This is a flask app that includes an authentication API and a logging system for admin users to view the logs of the users.
Install the requirements using pip
pip install -r requirements.txt
Run the app using the following command
python app.py
Add the following to your config file
DATABASE_NAME = "nuwe"
JWT_SECRET_KEY = "secret"
POST /register
Name | Type | Description |
---|---|---|
first_name | string | The first name of the user |
last_name | string | The last name of the user |
string | The email of the user | |
username | string | The username of the user |
role | string | The role of the user |
password | string | The password of the user |
{
"message": "User created successfully"
}
POST /login
Name | Type | Description |
---|---|---|
username | string | The username of the user |
password | string | The password of the user |
{
"access_token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9"
}
GET /home
Name | Type | Description |
---|---|---|
Authorization | string | The access token of the user |
{
"message": "Welcome back {current_user}! Your current role is {user_role}. Great to have you back."
}
The encryption algorithmm used is bcrypt. The password is hashed and stored in the database. When the user logs in, the password is hashed and compared to the hashed password in the database. I used bcrypt because it is a slow hashing algorithm and it is difficult to brute force.
I used the jwt token for the access control because it is a secure way to authenticate users and also to verify if a user is an admin or not which will be used for the logging system logic.
I used sqlite3 because it is a lightweight database and it is easy to use. It is also a good database for small applications. I used the database to store the user information and the logs of the users and also query the database to get the information. I created a utility file to handle the database operations and also to create the database tables.
GET /log
Name | Type | Description |
---|---|---|
Authorization | string | The access token of the user |
{
"latest_connections": [
{
"ip": "127.0.0.1",
"date": "Jul 03, 2023",
"http_verb": "GET",
"endpoint": "/log"
}
{
"ip": "127.0.0.1",
"date": "Jul 03, 2023",
"http_verb": "GET",
"endpoint": "/register"
}
],
"all_connections": [
{
"ip": "127.0.0.1",
"date": "Jul 01, 2023",
"http_verb": "GET",
"endpoint": "/home"
},
{
"ip": "127.0.0.1",
"date": "Jul 02, 2023",
"http_verb": "GET",
"endpoint": "/register"
}