Django Referral System is a Django-based application that serves as a template for building referral systems. It utilizes Django Rest Framework for creating RESTful APIs.
This app provides a simple foundation for implementing a referral system. It includes a custom user model with authentication.
- Clone repo
git clone https://github.com/Asadhimself/drf-referral.git
- Install dependecies
pip install poetry
poetry install
-
Rename .env.example to .env and set up your environment dependencies
-
Run migrations
python manage.py makemigrations
python manage.py migrate
- Run the app
python manage.py runserver
localhost:8000/api/docs
In this page (it's also home page) you can see automatically generated SwaggerUI docs.
POST /api/login/
curl -d 'phone_number=+998901234567' http://localhost:8000/api/login/
Response:
{
'phone_number': '+998901234567',
'otp': '1234',
}
When you get OTP you can use it only once. After you getting Auth token OTP become useless.
You can get auth token by sending second request:
curl -X POST \
-H "Content-Type: application/json" \
-d '{"phone_number": "+998901234567", "otp": "1234"}' \
http://localhost:800/api/login/
Response:
{
'url_account': '/api/account/',
'token': 'some-auth-token'
}
In order to authenticate you need to puth it into headers like shown in example:
Authorization: Token
GET /api/account/
curl -H 'Authorization: Token some-auth-token' http://localhost:8000/api/account/
{
"url_account":"/api/account/",
"phone_number":"+998901234567",
"username":"+998901234567",
"email":"",
"first_name":"",
"last_name":"",
"last_login":"2022-03-30T04:59:02.718663+03:00",
"date_joined":"2022-03-30T04:59:02.613466+03:00",
"invite":null,
"user_invite":{
"pk":2,
"key":"some-invite-key",
"account_set":[]
}
}
PUT /api/account/
curl -H 'Authorization: Token some-auth-token' -d 'username=Username' -X PUT http://localhost:8000/api/account/
{
"phone_number":"+998901234567",
"username":"Username",
"email":"",
"first_name":"",
"last_name":"",
"last_login":"2024-04-26T03:37:02.5332455+05:00",
"date_joined":"2024-04-26T03:37:02.5332455+05:00",
"invite":null,
"user_invite":{
"pk":2,
"key":"some-auth-key",
"account_set":[]
}
}
PUT /api/account/
curl -H 'Authorization: Token some-auth-token' -d 'invite=user-invite-key' -X PUT http://localhost:8000/api/account/
{
"phone_number":"+998901234567",
"username":"Username",
"email":"",
"first_name":"",
"last_name":"",
"last_login":"2022-03-30T04:59:02.718663+03:00",
"date_joined":"2022-03-30T04:59:02.613466+03:00",
"invite":"some-invite-key",
"user_invite":{
"pk":2,
"key":"user-invite-key",
"account_set":[]
}
}
This project served as a technical exercise for job application, but the employer ceased communication. The technical exercise details can be found here.