From 617e36dc1ede2a311dfd03f18432b31cbfe4c0f7 Mon Sep 17 00:00:00 2001 From: levental Date: Mon, 19 Sep 2016 14:55:18 +0200 Subject: Fixed #20705 -- Allowed using PasswordResetForm with user models with an email field not named 'email'. --- tests/auth_tests/models/with_custom_email_field.py | 23 ++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 tests/auth_tests/models/with_custom_email_field.py (limited to 'tests/auth_tests/models') diff --git a/tests/auth_tests/models/with_custom_email_field.py b/tests/auth_tests/models/with_custom_email_field.py new file mode 100644 index 0000000000..a98b02b8f1 --- /dev/null +++ b/tests/auth_tests/models/with_custom_email_field.py @@ -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() -- cgit v1.3