mirror of
https://github.com/django/django.git
synced 2025-10-24 14:16:09 +00:00
Fixed #20705 -- Allowed using PasswordResetForm with user models with an email field not named 'email'.
This commit is contained in:
23
tests/auth_tests/models/with_custom_email_field.py
Normal file
23
tests/auth_tests/models/with_custom_email_field.py
Normal file
@@ -0,0 +1,23 @@
|
||||
from django.contrib.auth.base_user import AbstractBaseUser
|
||||
from django.contrib.auth.models import BaseUserManager
|
||||
from django.db import models
|
||||
|
||||
|
||||
class CustomEmailFieldUserManager(BaseUserManager):
|
||||
def create_user(self, username, password, email):
|
||||
user = self.model(username=username)
|
||||
user.set_password(password)
|
||||
user.email_address = email
|
||||
user.save(using=self._db)
|
||||
return user
|
||||
|
||||
|
||||
class CustomEmailField(AbstractBaseUser):
|
||||
username = models.CharField(max_length=255)
|
||||
password = models.CharField(max_length=255)
|
||||
email_address = models.EmailField()
|
||||
is_active = models.BooleanField(default=True)
|
||||
|
||||
EMAIL_FIELD = 'email_address'
|
||||
|
||||
objects = CustomEmailFieldUserManager()
|
||||
Reference in New Issue
Block a user