A simple, customizable Django authentication package with JWT support, email verification, and password management
Project description
Django Simple Auth
A simple, customizable, and feature-rich authentication package for Django. It provides a complete solution for user registration, login, password management, and email verification, with support for custom user models and JWT authentication.
Table of Contents
- Features
- Installation
- Quick Start
- Configuration Reference
- Custom User Model Support
- API Documentation
- Template Customization
- Email Verification
Features
- Flexible Login: Log in with Username, Email, or Phone Number.
- Custom User Model Support: Seamlessly works with custom user models and extra fields (e.g., Avatar, Address).
- JWT Authentication: Built-in API endpoints for modern frontend integration.
- Email Verification: Integrated support for Resend to verify user emails.
- Password Management: Ready-to-use views for Password Reset and Password Change.
- Customizable: Override templates and forms easily.
- Beginner-Friendly: Clear error messages, helpful hints, and comprehensive documentation.
Quick Start
New to Django Simple Auth? Start here! 👉 QUICKSTART.md
Or run the setup checker:
python manage.py simpleauth_check
Installation
-
Install via pip:
pip install django-simple-auth-pkg
(For local development, navigate to the package directory and run
pip install -e .) -
Add to
INSTALLED_APPS: Open your project'ssettings.pyand add:INSTALLED_APPS = [ # ... default django apps ... 'rest_framework', 'rest_framework_simplejwt', 'simple_auth', # 'accounts', # Your custom app if you have one ]
-
Include URLs: Open your project's
urls.pyand add:from django.urls import path, include urlpatterns = [ # ... path('auth/', include('simple_auth.urls')), ]
-
Run Migrations:
python manage.py migrate
Quick Start
Once installed, you can access the following views immediately:
- Signup:
/auth/signup/ - Login:
/auth/login/ - Logout:
/auth/logout/ - Password Change:
/auth/password-change/ - Password Reset:
/auth/password-reset/
Configuration Reference
Add these settings to your settings.py to control the package behavior.
| Setting | Default | Description |
|---|---|---|
SIMPLE_AUTH_LOGIN_FIELD |
'username' |
Field used for login. Options: 'username', 'email', 'phone_number'. |
SIMPLE_AUTH_USER_FIELDS |
[] |
List of extra fields to include in the Signup form (e.g., ['first_name', 'avatar']). |
SIMPLE_AUTH_USE_JWT |
False |
Set to True to enable API endpoints for JWT authentication. |
SIMPLE_AUTH_EMAIL_VERIFICATION |
False |
Set to True to require email verification. |
RESEND_API_KEY |
None |
Your Resend API Key (required if email verification is on). |
LOGIN_REDIRECT_URL |
'/accounts/profile/' |
URL to redirect to after successful login. |
LOGOUT_REDIRECT_URL |
None |
URL to redirect to after logout. |
Example Configuration:
SIMPLE_AUTH_LOGIN_FIELD = 'email'
SIMPLE_AUTH_USER_FIELDS = ['first_name', 'last_name', 'avatar']
SIMPLE_AUTH_USE_JWT = True
SIMPLE_AUTH_EMAIL_VERIFICATION = True
RESEND_API_KEY = 're_123456...'
LOGIN_REDIRECT_URL = '/'
Custom User Model Support
This package is designed to work seamlessly with custom user models.
-
Define your model:
# accounts/models.py from django.contrib.auth.models import AbstractUser from django.db import models class CustomUser(AbstractUser): phone_number = models.CharField(max_length=15, unique=True) avatar = models.ImageField(upload_to='avatars/', blank=True, null=True)
-
Update Settings:
AUTH_USER_MODEL = 'accounts.CustomUser' SIMPLE_AUTH_USER_FIELDS = ['phone_number', 'avatar']
-
Important: If you have file fields (like
avatar), ensure your signup template form hasenctype="multipart/form-data".
Troubleshooting
Common Issues
Problem: "No module named 'simple_auth'"
Solution: Install the package: pip install django-simple-auth
Problem: "CSRF token missing or incorrect"
Solution: API endpoints don't need CSRF. Use /api/auth/api/ endpoints, not /api/auth/ (HTML views).
Problem: "Passwords do not match"
Solution: Ensure password and confirm_password are identical in your request.
Problem: "Current password is incorrect"
Solution: Double-check you're entering your current password, not the new one.
Problem: "Password must be at least 8 characters long"
Solution: Use a password with 8 or more characters.
Getting Help
- Check the Quickstart Guide
- See Examples
- Run
python manage.py simpleauth_checkto verify your setup - Open an issue on GitHub
License
MIT
API Documentation
If SIMPLE_AUTH_USE_JWT = True, the following endpoints are available under /auth/api/:
1. Signup
- Endpoint:
POST /auth/api/signup/ - Payload:
{ "username": "jdoe", "email": "jdoe@example.com", "password": "securepassword", "confirm_password": "securepassword", "phone_number": "1234567890" // Any extra field defined in settings }
- Response:
201 Createdwithaccessandrefreshtokens.
2. Login
- Endpoint:
POST /auth/api/login/ - Payload:
{ "username": "jdoe@example.com", // Or username/phone based on config "password": "securepassword" }
- Response:
200 OKwithaccessandrefreshtokens.
3. Password Change
- Endpoint:
POST /auth/api/password-change/ - Headers:
Authorization: Bearer <access_token> - Payload:
{ "old_password": "oldpassword", "new_password": "newpassword" }
4. Password Reset Request
- Endpoint:
POST /auth/api/password-reset/ - Payload:
{"email": "jdoe@example.com"}
5. Password Reset Confirm
- Endpoint:
POST /auth/api/password-reset-confirm/ - Payload:
{ "uidb64": "<uid from email>", "token": "<token from email>", "new_password": "newpassword" }
6. Resend Verification Email
- Endpoint:
POST /auth/api/resend-verification/ - Payload:
{"email": "jdoe@example.com"}
Template Customization
To customize the look and feel, create a directory named simple_auth inside your project's templates directory. You can override any of the following files:
simple_auth/base.html(Base layout)simple_auth/login.htmlsimple_auth/signup.htmlsimple_auth/password_reset_form.htmlsimple_auth/password_reset_done.htmlsimple_auth/password_reset_confirm.htmlsimple_auth/password_reset_complete.htmlsimple_auth/password_change_form.htmlsimple_auth/password_change_done.htmlsimple_auth/verification_sent.htmlsimple_auth/verification_success.html
Example simple_auth/login.html override:
{% extends 'base.html' %}
{% block content %}
<div class="my-custom-login-class">
<h2>Login to My App</h2>
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<button type="submit" class="btn btn-primary">Login</button>
</form>
</div>
{% endblock %}
Email Verification
To enable email verification:
- Set
SIMPLE_AUTH_EMAIL_VERIFICATION = True. - Set
RESEND_API_KEY = 're_...'. - When a user signs up,
is_activewill be set toFalse. - An email will be sent with a verification link.
- Clicking the link will activate the user and redirect to the success page.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_simple_auth_pkg-1.0.0.tar.gz.
File metadata
- Download URL: django_simple_auth_pkg-1.0.0.tar.gz
- Upload date:
- Size: 14.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4820c4c25a61c24e688b9d10cc8eacb54e763ddff9816276041d0f2b7f422f95
|
|
| MD5 |
b936df7127caa313516bfef983dc62ed
|
|
| BLAKE2b-256 |
1ce9b12628c903bb58ea675deac0a2258304ec7f1e47f8816b0603dde648dc3e
|
File details
Details for the file django_simple_auth_pkg-1.0.0-py3-none-any.whl.
File metadata
- Download URL: django_simple_auth_pkg-1.0.0-py3-none-any.whl
- Upload date:
- Size: 20.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
81b36485afa330cf5db709ebd5dbe4d7f8b66105c1cd9b839276100419f40097
|
|
| MD5 |
9d5c6517037f864b6a7db1338f49fc0f
|
|
| BLAKE2b-256 |
2076537d5a1ec5b0373e2f764f753299cf8f0124005a62b978e4eafc363178f4
|