This Django project implements a user management system with authentication and organization management using Django REST Framework.
-
Clone the repository:
git clone git@github.com:Laban254/user-authentication-and-organisation.git cd user-authentication-and-organisation
-
Build and run Docker containers:
docker-compose up --build
-
Apply database migrations:
docker-compose exec web python manage.py migrate
-
The application will be accessible at
http://localhost:8000
.
-
Clone the repository:
git clone git@github.com:Laban254/user-authentication-and-organisation.git cd user-authentication-and-organisation
-
Install dependencies:
pip install -r requirements.txt
-
Apply database migrations:
python manage.py migrate
-
Run the development server:
python manage.py runserver
-
The application will be accessible at
http://localhost:8000
.
-
POST /auth/register/
Registers a new user and creates a default organization.
Request Body:
{ "firstName": "string", "lastName": "string", "email": "string", "password": "string", "phone": "string" }
Successful Response:
{ "status": "success", "message": "Registration successful", "data": { "accessToken": "eyJh...", "user": { "userId": "string", "firstName": "string", "lastName": "string", "email": "string", "phone": "string" } } }
-
POST /auth/login/
Logs in a user with valid credentials.
Request Body:
{ "email": "string", "password": "string" }
Successful Response:
{ "status": "success", "message": "Login successful", "data": { "accessToken": "eyJh...", "user": { "userId": "string", "firstName": "string", "lastName": "string", "email": "string", "phone": "string" } } }
-
GET /api/users/int:id/
Retrieves the details of a specific user.
Successful Response:
{ "status": "success", "message": "User details retrieved", "data": { "userId": "string", "firstName": "string", "lastName": "string", "email": "string", "phone": "string" } }
-
GET /api/organisations/
Retrieves a list of organizations the logged-in user belongs to or created.
Successful Response:
{ "status": "success", "message": "Organisations retrieved", "data": { "organisations": [ { "orgId": "string", "name": "string", "description": "string" } ] } }
-
GET /api/organisations/int:orgId/
Retrieves the details of a specific organization.
Successful Response:
{ "status": "success", "message": "Organisation details retrieved", "data": { "orgId": "string", "name": "string", "description": "string" } }
-
POST /api/organisationsCreate/
Creates a new organization.
Request Body:
{ "name": "string", "description": "string" }
Successful Response:
{ "status": "success", "message": "Organisation created successfully", "data": { "orgId": "string", "name": "string", "description": "string" } }
-
POST /api/organisations/int:orgId/users/
Adds a user to a specific organization.
Request Body:
{ "userId": "string" }
Successful Response:
{ "status": "success", "message": "User added to organisation successfully" }
-
POST /api/token/
Obtain JWT token for authentication.
Request Body:
{ "username": "string", "password": "string" }
Successful Response:
{ "access": "string", "refresh": "string" }
To run test, be in the same directory as manage.py and run
python3 manage.py test accounts.tests.auth.spec
-
auth.spec.py
Contains unit tests and end-to-end tests for:
- Successful user registration
- Successful user login
- Validation errors for missing fields
- Duplicate email or userID errors
- Token generation and expiration checks
- Access control for organizations
This project is licensed under the MIT License. See the LICENSE file for details.
For any questions or inquiries, please contact:
- Laban254 - GitHub