A reusable Django app that provides a customizable user system for all Django projects. This app is designed to be general-purpose so it can be easily integrated into different projects.
- 🔑 Custom user model with Email and Username login support (
AUTH_USER_MODEL) - 🔒 2FA Authentication (OTP generation & SMS integration)
- 🚀 JWT Session Management (
rest_framework_simplejwt) - ⚡ Redis caching for OTP state and Attempt Tracking and Manage User session
- 📂 Clean architecture ("Fat Serializers, Skinny Views")
- 🛠️ Easily swappable SMS providers (Built-in Console and SMS.ir support)
-
Clone the repository into your Django project:
git clone https://github.com/parsaferdosi/UserApp.git
-
Add the
userandrest_framework_simplejwtapps to your DjangoINSTALLED_APPSinsettings.py:INSTALLED_APPS = [ ... 'rest_framework_simplejwt', 'user', ]
-
Configure your custom user model in
settings.py:AUTH_USER_MODEL = 'user.Account'
-
Configure Redis, SMS, and 2FA Settings in your
settings.py:# ------------------------- # UserApp Settings # ------------------------- # Redis Connection Settings REDIS_HOST = "localhost" REDIS_PORT = 6379 REDIS_PASSWORD = None REDIS_DATABASES = {"otp": 0, "cache": 1, "session": 2, "queue": 3} # SMS Provider Settings SMS_PROVIDER = "console" # Options: "console" or "sms_ir" # SMS_API_KEY = "your_sms_ir_api_key" # SMS_LINE_NUMBER = "your_sms_ir_line_number" # 2FA Settings TTL_2FA = 120 # Seconds until OTP expires MAX_2FA_ATTEMPTS = 3
-
Run migrations:
python manage.py makemigration python manage.py migrate
Once included in your main urls.py, the following REST API endpoints will be available:
POST /register/— Register a new accountPOST /login/— Request OTP via SMSPOST /login/authorization/— Verify OTP and receive JWT tokensPOST /logout/— Invalidate the current sessionGET /profile/— Retrieve user profilePUT /profile/— Update user profilePUT /profile/change_password/— Change user passwordDELETE /profile/delete_account/— Delete user accountPOST /token/refresh/— Refresh the JWT access token
UserApp/
├── user/ # Main Django app (Models, API Views, DRF Serializers)
├── utils/ # Helper modules (Redis Singleton Manager, SMS Providers, Generators)
├── LICENSE
├── README.md
└── .gitignore
This project is licensed under the MIT License – see the LICENSE file for details.
Parsa Ferdosi Zade
- GitHub: @parsaferdosi