Intelligent and Smart Supply Chain Management System
A Django-based authentication system with token-based authentication functionality.
- User registration
- User login with token generation
- Profile access and management
- Password change
- Password reset via email
- Token-based authentication
Copy the example environment file:
cp example.env .envMake sure the values are correctly set, especially:
DJANGO_SECRET_KEYPOSTGRES_*variables- Email SMTP credentials (if applicable)
docker compose up --buildThis will start:
- PostgreSQL database on port
15432 - Django user service on port
8001 - Adminer (DB UI) on port
8080
To initialize roles, use the init_roles management command. This command automates the creation of default roles.
Run the following command:
docker exec -it user_service python manage.py init_roles
Role.objects.create(id=5, name='Warehouse Manager', description='Manages warehouses')
Role.objects.create(id=6, name='Driver', description='Delivery personnel')
exit()-
User API: http://localhost:8001/api/v1/
-
Adminer UI: http://localhost:8080
- Server:
db - User:
postgres - Password:
postgres - DB:
postgres
- Server:
-
Clone the repository
git clone https://github.com/iransamarasekara/SCMS.git cd SCMS -
Create a virtual environment and activate it
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies
pip install -r requirements.txt
-
Create a
.envfile in the project root directory and add your environment variables (See the example .env file for required variables) -
Run migrations
python manage.py makemigrations python manage.py migrate
-
Create initial roles
python manage.py shell from accounts.models import Role Role.objects.create(id=1, name='Admin', description='Administrator with full access') Role.objects.create(id=2, name='Regular User', description='Standard user account') Role.objects.create(id=3, name='Supplier', description='Product supplier') Role.objects.create(id=4, name='Vendor', description='Product vendor') Role.objects.create(id=5, name='Warehouse Manager', description='Manages warehouses') Role.objects.create(id=6, name='Driver', description='Delivery personnel') exit()
-
Run the development server
python manage.py runserver
/api/v1/register/- Register a new user/api/v1/login/- Login and get an authentication token/api/v1/logout/- Logout and invalidate the token/api/v1/me/- Get the user profile/api/v1/me/update/- Update the user profile/api/v1/password/change/- Change the user password/api/v1/password/reset/- Request a password reset email/api/v1/password/reset-confirm/<uidb64>/<token>/- Confirm password reset
/api/v1/admin/users/- Get all users (admin only)/api/v1/admin/users/<user_id>/- Update specific user (admin only)/api/v1/admin/users/<user_id>/delete/- Delete specific user (admin only)
All protected endpoints require token authentication. Include the token in the request header:
Authorization: Bearer <your_token>
Run the tests with:
python manage.py testproject_root/
├── accounts/ # Main app directory
│ ├── migrations/ # Database migrations
│ ├── models.py # User, Token, and PasswordResetToken models
│ ├── tests.py # Authentication tests
│ ├── urls.py # URL configurations
│ └── views.py # API views
├── auth-service/ # Django project settings
│ ├── settings.py # Project settings
│ ├── urls.py # Main URL configurations
│ └── wsgi.py # WSGI configuration
├── .env # Environment variables
├── .gitignore # Git ignore file
├── manage.py # Django management script
└── README.md # Project documentation
- The system uses Django's built-in password hashing
- Tokens expire after 7 days
- Password reset tokens expire after 24 hours
- All sensitive data should be stored in the .env file and not committed to version control