This Django application implements a custom user model that uses email as the primary identifier instead of a username. The implementation extends Django's built-in authentication system while providing additional customization options.
- Email-based authentication
- Full name field
- Custom user manager with email normalization
- Proper password hashing
- Superuser creation support
- Integration with Django's permission system
The CustomUser
model extends Django's AbstractBaseUser
and PermissionsMixin
to provide a complete user authentication system.
email
(EmailField): Unique identifier for authenticationfull_name
(CharField): User's full nameis_active
(BooleanField): Designates whether the user account is activeis_staff
(BooleanField): Determines if the user can access the admin site
A custom manager class that handles user creation and superuser creation.
create_user(email, password=None, **extra_fields)
: Creates and saves a regular usercreate_superuser(email, password=None, **extra_fields)
: Creates and saves a superuser
- Add the custom user model to your Django settings:
AUTH_USER_MODEL = 'your_app_name.CustomUser'
- Run migrations:
python manage.py makemigrations
python manage.py migrate
# Create a regular user
user = CustomUser.objects.create_user(
email='user@example.com',
password='your_password',
full_name='John Doe'
)
# Create a superuser
superuser = CustomUser.objects.create_superuser(
email='admin@example.com',
password='admin_password',
full_name='Admin User'
)
Users can authenticate using their email address and password through Django's standard authentication backend.
- Passwords are automatically hashed using Django's password hashing system
- Email addresses are normalized before saving
- Built-in support for Django's permission system through PermissionsMixin
- Django 3.x or higher
- Python 3.x
Feel free to submit issues and enhancement requests.