Phometa is a secure phone book application built with Flask, SQLAlchemy, and PostgreSQL. It includes features such as user registration, login, contact management, spam number marking, and user search. The application uses JWT for user authentication and Flask-Migrate for database migrations.
- Python version >= 3.10
- PostgreSQL database
-
Clone the repository:
git clone https://github.com/yourusername/phometa.git cd phometa -
Create a virtual environment and activate it:
python -m venv venv source venv/bin/activate # On Windows use `venv\Scripts\activate`
-
Install the required packages:
pip install -r requirements.txt
-
Set up the PostgreSQL database: Create a new database in PostgreSQL.
CREATE DATABASE phometa;
-
Update the
SQLALCHEMY_DATABASE_URIvariable inapp.py: Openapp.pyand update theSQLALCHEMY_DATABASE_URIwith your local database URL.phometa.config['SQLALCHEMY_DATABASE_URI'] = 'postgresql://username:password@localhost:5432/Phometa'
-
Initialize the migration folder:
flask db init
-
Generate the migration scripts:
flask db migrate -m "Initial migration." -
Apply the migrations to the database:
flask db upgrade
-
Start the Flask application:
python app.py
-
The application will be accessible at
http://127.0.0.1:5000/.
-
URL:
/register -
Method:
POST -
Payload:
{ "name": "John Doe", "phone": "1234567890", "email": "john.doe@example.com", "password": "password123" } -
Response:
{ "message": "User created successfully." }
-
URL:
/login -
Method:
POST -
Payload:
{ "phone": "1234567890", "password": "password123" } -
Response:
{ "access_token": "your_access_token" }
-
URL:
/add-contact -
Method:
POST -
Headers:
{ "Authorization": "Bearer your_access_token" } -
Payload:
{ "name": "Jane Doe", "phone": "0987654321" } -
Response:
{ "message": "Contact added successfully." }
-
URL:
/mark-spam -
Method:
POST -
Headers:
{ "Authorization": "Bearer your_access_token" } -
Payload:
{ "phone": "0987654321" } -
Response:
{ "message": "Number marked as spam." }
-
URL:
/search -
Method:
POST -
Headers:
{ "Authorization": "Bearer your_access_token" } -
Payload:
{ "name": "Jane Doe", "phone": "0987654321" } -
Response:
{ "message": "User(s) Found", "data": [ { "name": "Jane Doe", "phone": "0987654321", "spam_reports": 0, "contact_name": "Jane", "email": "jane.doe@example.com" } ] }
-
URL:
/logout -
Method:
POST -
Headers:
{ "Authorization": "Bearer your_access_token" } -
Response:
{ "message": "User logged out successfully. Token Expired." }
The data.py script can be used to generate random data and test the API endpoints.
-
Update the API endpoint in
data.py:api_endpoint = "http://127.0.0.1:5000/"
-
Run the script:
python data.py
This script will register random users, log them in, add contacts, mark numbers as spam, and log out.